Skip to content

Commit

Permalink
Example code for ListBox
Browse files Browse the repository at this point in the history
  • Loading branch information
NotYoojun committed Nov 15, 2024
1 parent 3a84e64 commit ba1a81b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
<ListBox
x:Name="ListBox2"
Height="164"
d:DataContext="{d:DesignInstance Type=local:ControlPages.ListBoxPage}"
DataContext="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ui:Page}}}"
DisplayMemberPath="Item1"
ItemsSource="{Binding Fonts}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public List<Tuple<string, FontFamily>> Fonts
}
public ListBoxPage()
{
this.InitializeComponent();
InitializeComponent();
UpdateExampleCode();
}

private void ColorListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -66,9 +67,45 @@ private void ListBox2_Loaded(object sender, RoutedEventArgs e)

public void UpdateExampleCode()
{

Example1.Xaml = Example1Xaml;
Example2.Xaml = Example2Xaml;
Example2.CSharp = Example2CS;
}

public string Example1Xaml => $@"
<ListBox x:Name=""ListBox1"">
<sys:String>Blue</sys:String>
<sys:String>Green</sys:String>
<sys:String>Red</sys:String>
<sys:String>Yellow</sys:String>
</ListBox>
";

public string Example2Xaml => $@"
<ListBox x:Name=""ListBox2""
DataContext=""{{Binding RelativeSource={{RelativeSource Mode=FindAncestor, AncestorType={{x:Type ui:Page}}}}}}""
DisplayMemberPath=""Item1""
ItemsSource=""{{Binding Fonts}}""
Loaded=""ListBox2_Loaded""
SelectedValuePath=""Item2"" />
";

public string Example2CS => $@"
private List<Tuple<string, FontFamily>> _fonts = new List<Tuple<string, FontFamily>>()
{{
new Tuple<string, FontFamily>(""Arial"", new FontFamily(""Arial"")),
new Tuple<string, FontFamily>(""Comic Sans MS"", new FontFamily(""Comic Sans MS"")),
new Tuple<string, FontFamily>(""Courier New"", new FontFamily(""Courier New"")),
new Tuple<string, FontFamily>(""Segoe UI"", new FontFamily(""Segoe UI"")),
new Tuple<string, FontFamily>(""Times New Roman"", new FontFamily(""Times New Roman""))
}};
public List<Tuple<string, FontFamily>> Fonts
{{
get {{ return _fonts; }}
}}
";

#endregion

}
Expand Down

0 comments on commit ba1a81b

Please sign in to comment.