Skip to content

Commit

Permalink
Example code for InfoBar
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Nov 13, 2024
1 parent a1b9d5b commit 3a84e64
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 60 deletions.
60 changes: 16 additions & 44 deletions source/iNKORE.UI.WPF.Modern.Gallery/ControlPages/InfoBarPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
xmlns:ui="http://schemas.inkore.net/lib/ui/wpf/modern"
Title="InfoBar Page"
d:DesignWidth="800"
mc:Ignorable="d">
mc:Ignorable="d"
Loaded="Page_Loaded">
<StackPanel>
<local:ControlExample x:Name="Example1" HeaderText="A closable InfoBar with options to change its Severity.">
<local:ControlExample.Resources>
Expand All @@ -24,15 +25,17 @@
Title="Title"
IsOpen="True"
Message="Essential app message for your users to be informed of, acknowledge, or take action on."
Severity="Informational" />
Severity="Informational"
Closed="InfoBar_Closed"/>

</local:ControlExample.Example>
<local:ControlExample.Options>
<StackPanel>
<CheckBox
x:Name="IsOpenCheckBox1"
Content="Is Open"
IsChecked="{Binding IsOpen, ElementName=TestInfoBar1, Mode=TwoWay}" />
IsChecked="{Binding IsOpen, ElementName=TestInfoBar1, Mode=TwoWay}"
Click="CheckBox_Click"/>
<ComboBox
x:Name="SeverityComboBox"
ui:ControlHelper.Header="Severity"
Expand All @@ -46,15 +49,6 @@
</StackPanel>
</local:ControlExample.Options>

<local:ControlExample.Xaml>
<sys:String xml:space="preserve">
&lt;muxc:InfoBar
IsOpen=&quot;$(IsOpen)&quot;
Severity=&quot;$(Severity)&quot;
Title=&quot;Title&quot;
Message=&quot;Essential app message for your users to be informed of, acknowledge, or take action on.&quot; /&gt;
</sys:String>
</local:ControlExample.Xaml>
<local:ControlExample.Substitutions>
<local:ControlExampleSubstitution Key="Severity" Value="{Binding Value.SelectedValue, Source={StaticResource SeverityComboBox}, Mode=OneWay}" />
<local:ControlExampleSubstitution Key="IsOpen" Value="{Binding Value.IsChecked, Source={StaticResource IsOpenCheckBox1}, Mode=OneWay}" />
Expand All @@ -77,7 +71,9 @@
<CheckBox
x:Name="IsOpenCheckBox2"
Content="Is Open"
IsChecked="{Binding IsOpen, ElementName=TestInfoBar2, Mode=TwoWay}" />
IsChecked="{Binding IsOpen, ElementName=TestInfoBar2, Mode=TwoWay}"
Click="CheckBox_Click"/>

<ComboBox
x:Name="MessageComboBox"
ui:ControlHelper.Header="Message Length"
Expand All @@ -97,26 +93,8 @@
</ComboBox>
</StackPanel>
</local:ControlExample.Options>
<local:ControlExample.Xaml>
<sys:String xml:space="preserve">
&lt;muxc:InfoBar
IsOpen=&quot;$(IsOpen)&quot;
Title=&quot;Title&quot;
Message=&quot;$(DisplayMessage)&quot; &gt;
$(DisplayButton)
&lt;/muxc:InfoBar&gt;
</sys:String>
</local:ControlExample.Xaml>
<local:ControlExample.Substitutions>
<local:ControlExampleSubstitution Key="IsOpen" Value="{Binding Value.IsChecked, Source={StaticResource IsOpenCheckBox2}, Mode=OneWay}" />
<local:ControlExampleSubstitution
Key="DisplayMessage"
x:Name="DisplayMessage"
Value="A long essential app message..." />
<local:ControlExampleSubstitution
Key="DisplayButton"
x:Name="DisplayButton"
Value="" />
</local:ControlExample.Substitutions>
</local:ControlExample>
<local:ControlExample x:Name="Example3" HeaderText="A closable InfoBar with options to display the close button and icon">
Expand All @@ -141,27 +119,21 @@
<CheckBox
x:Name="IsOpenCheckBox3"
Content="Is Open"
IsChecked="{Binding IsOpen, ElementName=TestInfoBar3, Mode=TwoWay}" />
IsChecked="{Binding IsOpen, ElementName=TestInfoBar3, Mode=TwoWay}"
Click="CheckBox_Click"/>

<CheckBox
x:Name="IsIconVisibleCheckBox"
Content="Is Icon Visible"
IsChecked="{Binding IsIconVisible, ElementName=TestInfoBar3, Mode=TwoWay}" />
IsChecked="{Binding IsIconVisible, ElementName=TestInfoBar3, Mode=TwoWay}"
Click="CheckBox_Click"/>
<CheckBox
x:Name="IsClosableCheckBox"
Content="Is Closable"
IsChecked="{Binding IsClosable, ElementName=TestInfoBar3, Mode=TwoWay}" />
IsChecked="{Binding IsClosable, ElementName=TestInfoBar3, Mode=TwoWay}"
Click="CheckBox_Click"/>
</StackPanel>
</local:ControlExample.Options>
<local:ControlExample.Xaml>
<sys:String xml:space="preserve">
&lt;muxc:InfoBar
IsOpen=&quot;$(IsOpen)&quot;
IsIconVisible=&quot;$(IsIconVisible)&quot;
IsClosable=&quot;$(IsClosable)&quot;
Title=&quot;Title&quot;
Message=&quot;Essential app message for your users to be informed of, acknowledge, or take action on.&quot; /&gt;
</sys:String>
</local:ControlExample.Xaml>
<local:ControlExample.Substitutions>
<local:ControlExampleSubstitution Key="IsOpen" Value="{Binding Value.IsChecked, Source={StaticResource IsOpenCheckBox3}, Mode=OneWay}" />
<local:ControlExampleSubstitution Key="IsIconVisible" Value="{Binding Value.IsChecked, Source={StaticResource IsIconVisibleCheckBox}, Mode=OneWay}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ public InfoBarPage()
InitializeComponent();
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
DisplayMessage.Value = "A long essential app message...";
DisplayButton.Value = string.Empty;
}
string example2ActionButtonXaml = null;

private void SeverityComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Expand All @@ -56,8 +52,26 @@ private void SeverityComboBox_SelectionChanged(object sender, SelectionChangedEv
TestInfoBar1.Severity = InfoBarSeverity.Informational;
break;
}

UpdateExampleCode();
}

private void Page_Loaded(object sender, RoutedEventArgs e)
{
UpdateExampleCode();
}

private void CheckBox_Click(object sender, RoutedEventArgs e)
{
UpdateExampleCode();
}

private void InfoBar_Closed(InfoBar sender, InfoBarClosedEventArgs args)
{
UpdateExampleCode();
}


private void MessageComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (TestInfoBar2 == null) return;
Expand All @@ -66,13 +80,13 @@ private void MessageComboBox_SelectionChanged(object sender, SelectionChangedEve
{
string shortMessage = "A short essential app message.";
TestInfoBar2.Message = shortMessage;
DisplayMessage.Value = shortMessage;
}
else if (MessageComboBox.SelectedIndex == 1) //long
{
TestInfoBar2.Message = @"A long essential app message for your users to be informed of, acknowledge, or take action on. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus dolor vitae justo rutrum, ut lobortis nibh mattis. Aenean id elit commodo, semper felis nec.";
if (DisplayMessage != null) DisplayMessage.Value = "A long essential app message...";
}

UpdateExampleCode();
}

private void ActionButtonComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand All @@ -82,38 +96,64 @@ private void ActionButtonComboBox_SelectionChanged(object sender, SelectionChang
if (ActionButtonComboBox.SelectedIndex == 0) // none
{
TestInfoBar2.ActionButton = null;
if (DisplayButton != null) DisplayButton.Value = string.Empty;
example2ActionButtonXaml = null;
}
else if (ActionButtonComboBox.SelectedIndex == 1) // button
{
var button = new Button();
button.Content = "Action";
TestInfoBar2.ActionButton = button;
DisplayButton.Value = @"<muxc:InfoBar.ActionButton>
<Button Content=""Action"" Click=""InfoBarButton_Click"" />
</muxc:InfoBar.ActionButton> ";
example2ActionButtonXaml = @"
<ui:InfoBar.ActionButton>
<Button Content=""Action"" Click=""InfoBarButton_Click"" />
</ui:InfoBar.ActionButton> ";

}
else if (ActionButtonComboBox.SelectedIndex == 2) // hyperlink
{
var href = "https://docs.inkore.net/ui-wpf-modern/components/status/info-bar";
var link = new HyperlinkButton();
link.NavigateUri = new Uri("http://www.microsoft.com/");
link.NavigateUri = new Uri(href);
link.Content = "Informational link";
TestInfoBar2.ActionButton = link;
DisplayButton.Value = @"<muxc:InfoBar.ActionButton>
<HyperlinkButton Content=""Informational link"" NavigateUri=""https://www.example.com"" />
</muxc:InfoBar.ActionButton>";
example2ActionButtonXaml = $@"
<ui:InfoBar.ActionButton>
<ui:HyperlinkButton Content=""Informational link"" NavigateUri=""{href}"" />
</ui:InfoBar.ActionButton>";
}

UpdateExampleCode();
}

#region Example Code

public void UpdateExampleCode()
{
if (!this.IsLoaded) return;

Example1.Xaml = Example1Xaml;
Example2.Xaml = Example2Xaml;
Example3.Xaml = Example3Xaml;
}

#endregion
public string Example1Xaml => $@"
<ui:InfoBar x:Name=""TestInfoBar1"" Title=""Title"" IsOpen=""{TestInfoBar1.IsOpen}"" Severity=""{TestInfoBar1.Severity}""
Message=""Essential app message for your users to be informed of, acknowledge, or take action on."" />
";

public string Example2Xaml => $@"
<ui:InfoBar x:Name=""TestInfoBar2""
Title=""Title"" IsOpen=""{TestInfoBar2.IsOpen}""
Message=""{TestInfoBar2.Message}""> { (example2ActionButtonXaml != null ? "\r\n" : null) + example2ActionButtonXaml }
</ui:InfoBar>
";

public string Example3Xaml => $@"
<ui:InfoBar x:Name=""TestInfoBar3"" Title=""Title""
IsClosable=""{TestInfoBar3.IsClosable}"" IsIconVisible=""{TestInfoBar3.IsIconVisible}"" IsOpen=""{TestInfoBar3.IsOpen}""
Message=""Essential app message for your users to be informed of, acknowledge, or take action on."" />
";

#endregion
}
}

0 comments on commit 3a84e64

Please sign in to comment.