在自定义依赖项属性中未调用Setter

时间:2018-10-25 18:21:11

标签: c# wpf mvvm

    I have one UserControl name UCMultiShapeButton.xaml of Button with different shape as below:

    <Button Name="button"
                Margin="0,0,0,0"
                Click="onButtonClick"
                Command="{Binding Command,ElementName=UC}"
                CommandParameter="{Binding CommandParameter,ElementName=UC}"
                Style="{DynamicResource NoChromeButton}">
            <Grid HorizontalAlignment="Center" VerticalAlignment="Center">

                <Ellipse Name="shpCircle"
                         Width="{Binding Width,ElementName=UC}"
                         Height="{Binding Height,ElementName=UC}"
                         Visibility="Hidden" />

                <Rectangle Name="shpRectangle"
                           Width="{Binding Width,ElementName=UC}"
                           Height="{Binding Height,ElementName=UC}"
                           Visibility="Hidden" />
    </Button>

I have created its dependency property in UCMultiShapeButton.xaml.cs as below:

    public enum Shape
            {
                Circle,
                Rectangle
            }

            public Shape ButtonShape
            {
                get { return (Shape)GetValue(ButtonShapeProperty); }
                set { SetValue(ButtonShapeProperty, value); }
            }

    public static readonly DependencyProperty ButtonShapeProperty =
        DependencyProperty.Register("ButtonShape", typeof(Shape), typeof(UCMultiShapeButton),new PropertyMetadata(Shape.Rectangle));

在其他视图中,我将此用户控件称为:

<UC:UCMultiShapeButton x:Name="btnMultiShape"          

ButtonShape =“ {Binin TableShape,UpdateSourceTrigger = PropertyChanged,Mode = TwoWay}”  Height =“ {Binding BtnHeight}” Width =“ {Binding BtnWidth}”>

,并在其视图模型中创建该属性。 从视图模型设置TableShape属性时,不会设置ButtonShape依赖项属性的属性。

请让我知道是否需要更多信息。

0 个答案:

没有答案
相关问题