簡體   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