tags:

views:

18

answers:

1

Default Visibility enum contains

Collapsed
Hidden
Visible

I need another one name NotCreatable. When set Visibility to Notcreatable, current Element must not created on view level.

Because I have 2 class inherits from A

public Class B:A
{ Property B1;}
public Class C:A
{ Property C1;}

my xaml

<stackpanel DataContext="{Binding objectA}">
    <stackpanel Visiblity="{Binding isB,Converter={StaticResource Bool2Visible}}">
        <textbox text="{Binding B1}"/>
    </stackpanel>
    <Grid Visiblity="{Binding isC,Converter={StaticResource Bool2Visible}}">
        <ItemsControl Itemssource="{Binding C1}"/>
    </Grid>
</stackpanel>

Sometimes objectA is B, sometimes objectA is C. But my problem is when isC==true , First Stackpanel successfully hidden. But binding works. Following error shown System.Windows.Data Error: 40 : BindingExpression path error: 'B1' property not found on 'object' 'C'

A: 

The binding is probably executing even if the object is collapsed. Perhaps you should use the converter for binding instead?

<stackpanel DataContext="{Binding objectA}"> 
    <stackpanel> 
        <textbox text="{Binding objectA,Converter={StaticResource MyPropertyPicker}}"/> 
    </stackpanel> 
</stackpanel> 

And then let the MyPropertyPicker-converter choose what property to bind against?

Almund
Stackpanel and textbox is same on the My question example. But main project contains different controls binding.
ebattulga
That´s trickier indeed. Then I´d guess you will need to use some kind of itemtemplate which you switch with datatrigger. Or you could bind using a style where the style is triggered depending on the object type.
Almund
Check this one out, using an ItemsControl for binding of DataTemplates:
Almund
http://stackoverflow.com/questions/934873/using-stackpanel-as-contentcontrol-wpf
Almund