Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 将组合框值更新到数据库中_Wpf_Silverlight_Data Binding_Combobox - Fatal编程技术网

Wpf 将组合框值更新到数据库中

Wpf 将组合框值更新到数据库中,wpf,silverlight,data-binding,combobox,Wpf,Silverlight,Data Binding,Combobox,所以,我可能走错了方向,但我认为不管怎样,它都应该起作用。我有一个列表框,它从数据库中加载它的项 <UserControl.Resources> <DataTemplate x:Key="DataTemplateListBox"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="60" />

所以,我可能走错了方向,但我认为不管怎样,它都应该起作用。我有一个列表框,它从数据库中加载它的项

<UserControl.Resources>
    <DataTemplate x:Key="DataTemplateListBox">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="60" />
                <ColumnDefinition Width="130" />
            </Grid.ColumnDefinitions>

            <CheckBox Grid.Column="0" x:Name="cbNonFat" VerticalAlignment="Center" Margin="14,0,10,0" IsChecked="{Binding IsNonFat, Mode=TwoWay}">
            </CheckBox>

            <ComboBox HorizontalAlignment="Left" Width="120" Grid.Column="4" Name="cbbSeason"  Margin="0,0,10,0" Tag="{Binding Season, Mode=TwoWay}" Loaded="cbbSeason_Loaded" SelectionChanged="cbbSeason_SelectionChanged">
                <ComboBoxItem Content="Year Round" Tag="0"/>
                <ComboBoxItem Content="Spring/Summer" Tag="1"/>
                <ComboBoxItem Content="Fall/Winter" Tag="2"/>
                <ComboBoxItem Content="Featured" Tag="3"/>
            </ComboBox>

        </Grid>
    </DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
    <ListBox Name="lbFlavors" ItemTemplate="{StaticResource DataTemplateListBox}"/>
</Grid>
然后,当选择更改时,我更新标记:

    private void cbbSeason_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        (sender as ComboBox).Tag = (cbbSeason.SelectedItem as ComboBoxItem).Content.ToString();
    }

当我将更改保存回数据库时,复选框更改成功,但组合框更改失败。如果我在cbbSeason_SelectionChanged事件上设置断点,则标记根本不会得到更新,显然这就是问题所在,但我不知道为什么它不会得到更新。

如果有人感兴趣,我将底部代码更改为以下代码以修复它:
private void cbbSeason\u SelectionChanged(对象发送者,SelectionChangedEventArgs e){foreach(ComboBoxItem cbi in(发送者作为ComboBox.Items){if(Convert.ToInt16(cbi.Tag)=(发件人作为组合框)。SelectedIndex){(发件人作为组合框)。Tag=cbi.Content;break;}}}}
如何将更改保存到数据库?
    private void cbbSeason_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        (sender as ComboBox).Tag = (cbbSeason.SelectedItem as ComboBoxItem).Content.ToString();
    }