Click here to Skip to main content
16,021,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All!

I have Window which uses another UserControls. Those controls are loaded and used one in time. Loaded controls varies but one thing is commom, They have dependency property called IsValid. I like to bind that property to my main window button.

How do I achieve that?

Here is example of my problem

HTML
<window x:class="Example.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <StackPanel>       
                <!--Here we have dynamically loaded usercontrols. Control varies, but all have dependency property IsValid-->

                <ContentControl x:Name="DynamicContent"/>
                
                <!--Here Bind buttons IsEnabled to UserControl IsValid property-->                <Button Content="myButton" IsEnabled="???"></Button> 
       </StackPanel>
    </Grid>
</Window></window>


Hope you got idea :)

Cheers!
Posted

1 solution

Seems like the question isn't quite the right one. The binding on the button should be to a property on the view model (ContentValid or something). The question you really want to ask is what that property should do.

You must be choosing the control to include based on some criteria – hopefully in the view model. Have all the controls implement an interface (which includes just that one property), have the view model expose a property of that type which is the control to be shown, and the ContentValid property can then just look in the property by CurrentDynamicControl.IsValid.

(The interface may also need to expose a UserControl, which would be implemented thus:
public UserControl UserControl { get { return this; } }

... if you want to use that same property on the view model to actually populate ContentControl, which would probably be for the best.)
 
Share this answer
 
Comments
paleGegg0 18-Aug-11 7:12am    
wise words! I did small demo and I think it will work also my solution also! thanks for the tip!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900