现在的位置: 首页 > 综合 > 正文

WPF 一些容易忘记的控件属性

2011年06月03日 ⁄ 综合 ⁄ 共 904字 ⁄ 字号 评论关闭

1、ListBox:

1>listbox获取静态的Fonts.SystemFontFamilies属性,TextBox绑定SelectedItem。点击listbox选中项时,textbox改变字体

 <ListBox Grid.Row="0" ItemsSource="{x:Static Fonts.SystemFontFamilies}" Margin="5" Name="lstFonts"/>

   <TextBox 
           FontFamily="{Binding ElementName=lstFonts, Path=SelectedItem}"
           TextAlignment="Center" TextWrapping="Wrap">
        The quick brown fox jumps over the lazy dog
      </TextBox>

2>在listBox1_SelectionChanged事件里面选中的是里面的整个子控件,所以需要

 <ListBox  Name="listBox1" Width="120" Height="52"  SelectionChanged="listBox1_SelectionChanged" >

<ListBoxItem Tag="Red">Red</ListBoxItem>

<ListBoxItem Tag="Yellow">Yellow</ListBoxItem>

<ListBoxItem>Blue</ListBoxItem>

</ListBox>

 ((ListBoxItem)listBox1.SelectedItem).Content;可以获取里面的内容:Red,Yellow,Blue。

 ((ListBoxItem)listBox1.SelectedItem).Tag,可以获取Tag值。

<TextBlock Name="textBlock1" Foreground="{Binding ElementName=listBox1,Path=SelectedItem.Content}"  />;用于绑定内容,改变textblock的颜色。

2、Slider

抱歉!评论已关闭.