原創|其它|編輯:郝浩|2009-12-24 09:53:29.000|閱讀 1526 次
概述:好了,COMBOX常用就這么多了,它和LISTBOX使用都一樣,特別注意就是LISTBOX還是內容控件但是在使用的時候就不用這樣使用:
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
很高興能再次和大家分享,多的不說了,繼續開始.......
選擇控件:checkbox控件和radiobutton控件
<StackPanel Background="White" VerticalAlignment="Center">
<CheckBox Content="中間狀態" IsThreeState="True" IsChecked="" Margin="20"></CheckBox>
<CheckBox Content="選中" IsThreeState="True" IsChecked="true" Margin="20"></CheckBox>
<CheckBox Content="未選中" IsThreeState="True" IsChecked="false" Margin="20"></CheckBox>
</StackPanel>
<StackPanel Background="White" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal">
<TextBlock Text="請選擇性別:"></TextBlock>
<RadioButton Content="男" Margin="20" IsChecked="true"></RadioButton>
<RadioButton Content="女" Margin="20" IsChecked="false"></RadioButton>
</StackPanel>
<StackPanel>
<RadioButton Content="1" GroupName="g1" Margin="10">
</RadioButton>
<RadioButton Content="2" GroupName="g1" Margin="10"></RadioButton>
<RadioButton Content="3" GroupName="g1" Margin="10"></RadioButton>
</StackPanel>
</StackPanel>
注意:checkbox控件有個很重要的屬性isthreestate,它可以支持3中狀態,選中、未選中、中間狀態,比.NET的CHECKBOX強大吧 ,嘿嘿
在使用RADIOBUTTON要注意,如果RADIOBUTTON處于同一容器,就不需要設置GROUPNAME來識別.radiobutton控件屬于內容控件,我們就可以自定義它的樣式了,這里就不多講了吧,前面一篇有例子.
slider控件:范圍控件
<StackPanel Background="White" VerticalAlignment="Center">
<TextBlock Text="默認slider控件" Margin="10"></TextBlock>
<Slider x:Name="sa" Margin="5" Maximum="100" Minimum="0" Value="20"></Slider>
<TextBlock Text="垂直SILDER控件"></TextBlock>
<Slider x:Name="sb" Margin="5" Maximum="100" Minimum="0" Orientation="Vertical" Height="180" IsDirectionReversed="False" ValueChanged="sb_ValueChanged"></Slider>
<TextBlock x:Name="myvalue" Margin="20"></TextBlock>
</StackPanel>
private void sb_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
this.myvalue.Text = "當前值:"+this.sb.Value;
}
屬性介紹:maxinum:設置控件的最大值,minimun:設置控件數字范圍的最小值,value是當前值,isdirctinoreversed:設置控件的增加方向,如果為FALSE,方向朝上就增加,反之..,orientation:設置控件的方向有垂直和水平
列表控件:combox控件和listbox控件
兩個控件擁有共同的使用方法,我這里就只講解combox的使用
<StackPanel Background="White" VerticalAlignment="Center">
<ComboBox Width="300">
<ComboBoxItem>
<ComboBoxItem.Content>
<Rectangle Fill="Red" Width="200" Height="30"></Rectangle>
</ComboBoxItem.Content>
</ComboBoxItem>
<ComboBoxItem>
<ComboBoxItem.Content>
<TextBlock Text="你好"></TextBlock>
</ComboBoxItem.Content>
</ComboBoxItem>
</ComboBox>
</StackPanel>
首先combox屬于內容控件可以自定義,接下來就演示動態創建combox中的內容
定義實體類: public class Category
{
public int ID {get;set; }
public string Name { get; set; }
public int Count { get; set; }
}
動態綁定到combox中
public ListControl()
{
InitializeComponent();
this.Loaded+=new RoutedEventHandler(ListControl_Loaded);
}
public void ListControl_Loaded(object sender, RoutedEventArgs e)
{
List<Category> list = new List<Category> {
new Category{ID=1,Name="命令控件",Count=10},
new Category{ID=2,Name="選擇控件",Count=20},
new Category{ID=3,Name="列表控件",Count=30},
};
this.morecombox.ItemsSource = list;
}
前臺:
<StackPanel Background="White" VerticalAlignment="Center">
<ComboBox x:Name="mycombox" Width="200" Height="30" DisplayMemberPath="Name"></ComboBox>
</StackPanel>
<StackPanel Background="White" VerticalAlignment="Top">
<ComboBox x:Name="morecombox" Width="200" Height="30" SelectionChanged="morecombox_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Width="260" Orientation="Horizontal">
<TextBlock Text="{Binding ID}"></TextBlock>
<TextBlock Text="."></TextBlock>
<TextBlock Text="{Binding Name}"></TextBlock>
<TextBlock Text=" ( "></TextBlock>
<TextBlock Text="{Binding Count}" Foreground="Red"></TextBlock>
<TextBlock Text=" ) "></TextBlock>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<TextBlock x:Name="info"></TextBlock>
</StackPanel>
屬性介紹:Displaymemberpath獲取和設置顯示的名稱,itemssource:數據原集合,itemtemplate:列的模板類似于.NET中GRIDVIEW中的模板列,如果還要獲取選中的某一行selectindex或者selectitem屬性,還有一個常用的就是selectchanged事件
private void morecombox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Category ca = this.morecombox.SelectedItem as Category;
this.info.Text = ca.Name;
}
好了,COMBOX常用就這么多了,它和LISTBOX使用都一樣,特別注意就是LISTBOX還是內容控件但是在使用的時候就不用這樣使用:<listbox.content>貌似沒有吧,就直接使用<listboxitem>下面直接加就行了。。。。。。。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn