Tuesday, October 14, 2014

Data Binding in a nested element of a usercontrol to an ENUM in WPF

In .cs file

public enum Alignment
    {
        Horizontal,
        Vertical
    }

public Alignment UserAlignment

        {
            get
            {
                return _alignment;
            }
            set
            {
                _alignment = value;
            }
        }

In XAML file

xmlns:local="clr-namespace:MyNameSpace"
x:Name="MyControl"
.
.
.
.
.
.
<DataTrigger Binding="{Binding ElementName=MyControl,Path=UserAlignment}" Value="{x:Static local:Alignment.Vertical}">
                                    <Setter TargetName="TargetElement" Property="TargetProperty" >
                                        <Setter.Value>
Somevalue                  
                                        </Setter.Value>
                                    </Setter>
                                </DataTrigger>

No comments:

Post a Comment