简体   繁体   English

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

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

I made a usercontrol with several element inside (toggles, button, text box, etc...). 我做了一个用户控件,里面有几个元素(切换,按钮,文本框等)。 I'm using this usercontrol inside an other one, and load this final usercontrol at runtime and on my final application. 我正在另一个用户控件中使用此用户控件,并在运行时和最终应用程序上加载此最终用户控件。 I'm a little lost with dependency property, I would like to access the properties of the very first from my application. 我对依赖属性有些迷茫,我想从我的应用程序访问第一个属性。

The first usercontrol is called "Ch_Parameters" : 第一个用户控件称为“ 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">

I'm trying to first communicate with a toggle button contained in "Ch_Parameters" and its properties "IsChecked" 我试图首先与“ 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}"/>

and here is a the code for the property 这是该属性的代码

        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); }
    }

Now this usercontrol is used in other one called cmix : 现在,此用户控件已在另一个名为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">

here : 这里 :

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

and the code for the cmix property : 以及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); }
    }

but, when I use the usercontrol "cmix" and load it at runtime, the property FLIPX from the Ch_Parameters usercontrol is not outputing anything when I trigger the toggle button. 但是,当我使用用户控件“ cmix”并在运行时加载它时,触发触发按钮时,Ch_Parameters用户控件的FLIPX属性不会输出任何内容。

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

Is there a specific method to use properties from usercontrol inside an other usercontrol ? 是否存在使用其他用户控件内的用户控件属性的特定方法?

Here is the solution that worked for me, as I in fact had the exact same problem : 这是对我有用的解决方案,因为我实际上有完全相同的问题:

Binding DependencyProperty in nested user controls 在嵌套用户控件中绑定DependencyProperty

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

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