Talbar hidden and error binding



  • I've got the

    <ToolbarTray Visibility="{Binding SomeProperty}">
         <Toolbar>
            <Checkbox IsEnabled="{Binding IsEnabled}/"
          </Toolbar>
    </Toolbar>
    

    and two classes as possible data context - for two different windows.

    class ToolbarContextOne 
    {
       public Visibility SomeProperty {get;set;} 
    }
    class ToolbarContextTwo:ToolbarContextOne
    {
       public bool IsEnabled {get;set;}
    }
    

    I'm using a Tulbar as an example in a few situations. To show different data in different windows, I use different dates of context. When I don't need the above section, I'm just putting someProperty in Visibility. Collapsed. But I still get binding error for IsEnabled. Obviously, the passer is trying to fulfil all binding expressions. Is there a way to get him not to do this in the hidden section of the xaml?



  • Probably a cleaner way through. DataTemplate

    Put it somewhere in resources (e.g. global, or localized through the window or in the window) UserControl) such as:

    <DataTemplate DataType="{x:Type local:ToolbarContextOne}">
        <ToolbarTray Visibility="{Binding SomeProperty}">
            <Toolbar>
                <Checkbox IsEnabled="False"/>
            </Toolbar>
        </Toolbar>
    </DataTemplate>
    

    <DataTemplate DataType="{x:Type local:ToolbarContextTwo}">
    <ToolbarTray Visibility="{Binding SomeProperty}">
    <Toolbar>
    <Checkbox IsEnabled="{Binding IsEnabled}"/>
    </Toolbar>
    </Toolbar>
    </DataTemplate>

    Well, that's where you were. ToolbarTrayJust

    <ContentPresenter Content="{Binding}"/>

    However, ContentPresenter Find the right one. DataTemplate and use it.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2