繁体   English   中英

其他用户控件中的usercontrol。 如何使用属性?

[英]usercontrol inside an other user control. How to use properties?

我做了一个用户控件,里面有几个元素(切换,按钮,文本框等)。 我正在另一个用户控件中使用此用户控件,并在运行时和最终应用程序上加载此最终用户控件。 我对依赖属性有些迷茫,我想从我的应用程序访问第一个属性。

第一个用户控件称为“ Ch_Parameters”:

<UserControl
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:CustomControlTest"
         xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="CustomControlTest.ChannelParameters"
         mc:Ignorable="d" 
         x:Name="Ch_Parameters"
         d:DesignHeight="247.465" d:DesignWidth="436.624">

我试图首先与“ Ch_Parameters”及其属性“ IsChecked”中包含的切换按钮进行通信

<ToggleButton x:Name="Flip_X" Content="FLIP X" Style="{DynamicResource BaseToggleButtonStyle}" IsChecked="{Binding Path=DataContext.Flip_X, ElementName=Ch_Parameters, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

这是该属性的代码

        public static readonly DependencyProperty FlipXProperty =
    DependencyProperty.Register("FlipX", typeof(bool), typeof(ChannelParameters), new PropertyMetadata(true));

    [Bindable(true)]
    public bool FlipX
    {
        get { return (bool)this.GetValue(FlipXProperty); }
        set { this.SetValue(FlipXProperty, value); }
    }

现在,此用户控件已在另一个名为cmix的控件中使用:

         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:CustomControlTest"
         x:Name="cmix"
         xmlns:System="clr-namespace:System;assembly=mscorlib" x:Class="CustomControlTest.C_MiX_UserInterface"
         mc:Ignorable="d" d:DesignWidth="674.669" d:DesignHeight="337.953">

这里 :

<local:ChannelParameters FlipX="{Binding Path=Datacontext.VidFlipX, ElementName=cmix, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>

以及cmix属性的代码:

        public static readonly DependencyProperty VidFlipXProperty =
    DependencyProperty.Register("VidFlipX", typeof(bool), typeof(C_MiX_UserInterface), new PropertyMetadata(true));

    [Bindable(true)]
    public bool VidFlipX
    {
        get { return (bool)this.GetValue(VidFlipXProperty); }
        set { this.SetValue(VidFlipXProperty, value); }
    }

但是,当我使用用户控件“ cmix”并在运行时加载它时,触发触发按钮时,Ch_Parameters用户控件的FLIPX属性不会输出任何内容。

var uiElement = (C_MiX_UserInterface)UIElementOut[i];
var toggle = uiElement.VidFlipX;

是否存在使用其他用户控件内的用户控件属性的特定方法?

这是对我有用的解决方案,因为我实际上有完全相同的问题:

在嵌套用户控件中绑定DependencyProperty

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM