依赖项属性在用户控件中不起作用 [英] Dependency property not working in user control

查看:75
本文介绍了依赖项属性在用户控件中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖项属性,该属性设置是否需要一个字段(它背后的一些业务逻辑).我有一个包含ComboBox的下拉列表用户控件.我在usercontrol组合框的XAML中设置了此代码,但是未传递依赖项属性.我缺少什么吗?

以下是包含依赖项属性传递的行:

I've a dependency property that sets whether or not a field is required (some business logic behind it). I have a drop-list user control that contains a ComboBox. I set up this code in the XAML of the combo box of the usercontrol, but the dependency property is not being passed through. Is there something I'm missing?

Here's the line containing the dependency property pass-through:

XYZCoreUI:DPs.Required="{Binding ElementName=FacilityDropListControl, Path=XYZCoreUI:DPs.Required}"



以及控件的整个XAML代码:



And the entire XAML code of the control:

<UserControl x:Class="XYZ.FacilityDropList" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:XYZCoreUI="clr-namespace:XYZ.CoreUI" 
    x:Name="FacilityDropListControl" Loaded="OnLoaded" IsEnabledChanged="FacilityDropListControl_IsEnabledChanged" >
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/XYZ;component/Themes/GlobalData.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid>
        <ComboBox  Name="cbSearchFacility" IsEditable="True" 
                SelectedValue="{Binding ElementName=FacilityDropListControl, Path=SelectedValue}"
                SelectedValuePath="FAC_ID" DisplayMemberPath="FAC-NAME"
                ItemsSource="{Binding Source={StaticResource PermissibleFacilityList}, Mode=OneWay}"
                Width="{Binding ElementName=FacilityDropListControl, Path=Width}"
                Tag="{Binding ElementName=FacilityDropListControl, Path=Tag}"
                XYZCoreUI:DPs.Required="{Binding ElementName=FacilityDropListControl, Path=XYZCoreUI:DPs.Required}"
            >
        </ComboBox>
    </Grid>

</UserControl>

推荐答案

将其注册为DependencyProperty的代码背后的样子是什么?
What's the code-behind look like where you register it as a DependencyProperty?


这篇关于依赖项属性在用户控件中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆