开发者

WPF Databinding to ComboBox and also toggle its visibility

开发者 https://www.devze.com 2023-01-22 02:36 出处:网络
There are two issues that iam facing. One is binding a collection to combobox In code: private ObservableCollection<string> errList;

There are two issues that iam facing. One is binding a collection to combobox

In code:

private ObservableCollection<string> errList;

Initially its empty and then i add items to it.

In XAML:

<comboBox ItemsSource="{Binding errList}" IsSynchronizedWithCurrentItem="True"

Isnt this enough to get it done. But no items are seen in the combobox.

Second is toggling the visibility of the combobox when items are present.

<combobox Visibility="{ Binding ElementName=Page1, Path=ItemsPresent, Converter={StaticResource booltoVis} }"

ItemsPresent is a property which returns true of errL开发者_JAVA百科ist has items more than 0. But this is not working.

Please Help


I don't think you can bind to a private field, instead after filling your collection you can do the following:

YourComboBoxName.ItemsSource = errList;

For the visibility you need to do self binding like this:

<ComboBox Visibility="{Binding Path=ItemsPresent, RelativeSource={RelativeSource Self}, Converter={StaticResource booltoVis}}"/>
0

精彩评论

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