开发者

ComboBox which is bound to a db table should initially be blank

I have a WPF combobox control bound to a edm field in a database table. This works fine except that it enters the first value in the control when it starts which is not wanted. Heres the xaml

<ComboBox x:Name="cbMeasure" 
          Width="104" 
          ItemsSource="{Binding Source={StaticResource ddMe开发者_开发知识库asureViewSource}}" 
          DisplayMemberPath="Measure"
          IsSynchronizedWithCurrentItem="True"
          SelectedValuePath="Measure" 
          SelectedValue="{Binding Measure1}"/>

If I just hard code the control it doesn't put the first value in the variable. Heres what that xaml looks like

<ComboBox x:Name="cbMeasure" Width="104" Text="{Binding Measure1}">
        <TextBlock Text="one"/>
        <TextBlock Text="two"/>
        <TextBlock Text="three"/>
        <TextBlock Text="four"/>
</ComboBox>

What do I have to do to make the database bound combobox start with an empty value the way the textbox combobox does? This is a problem as it puts the first value in the SelectedValue bound to a variable (Measure1).

The db table ddMeasure looks like:

RID    Measure
---    -------
1      One
2      Two
3      Three
4      Four

so "One" in put into the ComboBox selection and Measure1 variable is populated as well.


OK I found the solution to this. You have to set the property IsSynchronizedWithCurrentItem to false which I thought I had tried but I think I just removed that property and the default must be true. So the xaml looks like

<ComboBox x:Name="cbMeasure"
       Width="104"
       ItemsSource="{Binding Source={StaticResource ddMeasureViewSource}}"
       DisplayMemberPath="Measure"
       IsSynchronizedWithCurrentItem="False"
       SelectedValuePath="Measure"
       SelectedValue="{Binding Measure1}"/>

Hope this helps others who try to find info on this type of binding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜