0

用户控件.vb 文件

Imports System.Data
Imports Orion_Magnetics_Ascend.StrategicAlliance

Public Class usrValueSet

    Public WriteOnly Property LabelPropertyValueSet() As String
        Set(ByVal value As String)
            lblValueSetsName.Text = value
        End Set
    End Property

End Class

用户控件.xaml 文件

<UserControl x:Class="usrValueSet"
             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" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40">
            </RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150"></ColumnDefinition>
         </Grid.ColumnDefinitions>
        <TextBlock Name="lblValueSetsName" Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>

    </Grid>
</UserControl>

示例页面上使用的用户控件如下所示

<local:usrValueSet x:Name="TFR_uvsCurrentLimitingFusePanelRating" Master="CurrentLimitingFusePanelRating" LabelPropertyValueSet="{DynamicResource TFR_tbRating}"   MaxTextLength="25"></local:usrValueSet>

如果您可以在“LabelPropertyValueSet”上方看到我已为其分配了动态资源

但它给了我错误

不能在“usrValueSet”类型的“LabelPropertyValueSet”属性上设置“DynamicResourceExtension”。只能在 DependencyObject 的 DependencyProperty 上设置“DynamicResourceExtension”。

像上面一样。。

请问有人知道如何将动态资源分配给 usercontrol 属性...?

4

1 回答 1

0

usercontrol.vb 文件,您需要更改以下内容需要更改此属性 DependencyProperty 并进行以下更改

Public Shared ReadOnly MyBorderBackgroundProperty As DependencyProperty = DependencyProperty.Register("LabelPropertyValueSet", GetType(String), GetType(usrValueSet), New FrameworkPropertyMetadata(AddressOf OnBackChanged))

        Private Shared Sub OnBackChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
            Dim sender = DirectCast(d, usrValueSet)
            sender.lblValueSetsName.Text = e.NewValue
            'lblValueSetsName.Text = e.NewValue
            ' Put a breakpoint here
        End Sub


    Public WriteOnly Property LabelPropertyValueSet() As String
            Set(ByVal value As String)
                SetValue(MyBorderBackgroundProperty, value)
            End Set
        End Property

之后,您可以将动态资源值分配给 usercontrol 属性,如下所示

  <local:usrValueSet x:Name="TFR_uvsExpulsionFusePanelRating" Master="ExpulsionFusePanelRating"  LabelPropertyValueSet="{DynamicResource ResourceKey=TFR_tbRating}" MaxTextLength="25"></local:usrValueSet>
于 2012-06-02T13:49:33.477 回答