弄了个ComboBox下拉菜单{0,1,...,7}然后我想通过在下拉菜单中选择一项数值在Label控件显示出来,达到数据同步的效果。请问怎么实现啊?
还有怎么获取系统时间啊?我想一起在Label控件中显示出来。comboboxwpflabel控件绑定

解决方案 »

  1.   

    <Window x:Class="WpfApplication3.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            Title="MainWindow" Height="350" Width="525">
        <Grid>
    <Grid.RowDefinitions>
    <RowDefinition Height="*" />
    <RowDefinition Height="3*" />
    </Grid.RowDefinitions>
    <Label Content="{Binding ElementName=comb, Path=SelectedValue.Content, Mode=OneWay}" />
    <ComboBox Grid.Row="1" Height="23" HorizontalAlignment="Left" Width="120" Name="comb" >
    <ComboBoxItem Content="1"  />
    <ComboBoxItem Content="2" />
    <ComboBoxItem Content="3" />
    <ComboBoxItem Content="4" />
    <ComboBoxItem Content="5" />
    <ComboBoxItem Content="6" />
    <ComboBoxItem Content="7" />
    </ComboBox>
    </Grid>
    </Window>
      

  2.   

    自己解决了。。
        public class Axonia
        {
            public string axoniaID { set; get; }
            public string tWeight { set; get; }
        }    public class AxoniaArr : ObservableCollection<Axonia>
        {
            public AxoniaArr()
            {
                this.Add(new Axonia { tWeight = "6t", axoniaID = "0" });
                this.Add(new Axonia { tWeight = "10t", axoniaID = "1" });
                this.Add(new Axonia { tWeight = "10t", axoniaID = "2" });
                this.Add(new Axonia { tWeight = "14t", axoniaID = "3" });
                this.Add(new Axonia { tWeight = "18t", axoniaID = "4" });
                this.Add(new Axonia { tWeight = "12t", axoniaID = "5" });
                this.Add(new Axonia { tWeight = "22t", axoniaID = "6" });
                this.Add(new Axonia { tWeight = "0t", axoniaID = "7" });
            }
        }<Window x:Class="ComboBox_Binding_sample.W02"  
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
        Title="W02" Height="130" Width="270"  
        xmlns:c="clr-namespace:ComboBox_Binding_sample">  
        <Window.Resources>  
            <c:AxoniaArr x:Key="ec"/>  
        </Window.Resources>  
        <Grid>  
            <Grid.RowDefinitions>  
                <RowDefinition Height="*"/>  
                <RowDefinition Height="*"/>  
            </Grid.RowDefinitions>  
    <ComboBox Width="160" Height="25" x:Name="TBAxonia" FontSize="14" ItemsSource="{StaticResource ec}" DisplayMemberPath="axoniaID" SelectedValuePath="tWeight"> <Label Background="#FFFFFFFF" x:Name="TB" Width="160" Height="25" BorderThickness="1,1,1,1" Content="{Binding ElementName=TBAxonia,Path=SelectedValue}"/>    </Grid>  
    </Window>