usercontrol.vb file
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>
如果你能在上面看到"标签属性值集",我已经为它分配了动态资源
但它给了我错误
不能在类型为"usrValueSet"的"LabelPropertyValueSet"属性上设置"DynamicResourceExtension"。"DynamicResourceExtension"只能在DependencyObject的DependencyProperty上设置。
像上面一样..
请有人知道如何将动态资源分配给用户控件属性...?
用户控件.vb您需要更改的文件 以下内容需要更改 使此属性依赖属性并执行以下更改
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
之后,您可以将动态资源值分配给用户控件属性像下面一样
<local:usrValueSet x:Name="TFR_uvsExpulsionFusePanelRating" Master="ExpulsionFusePanelRating" LabelPropertyValueSet="{DynamicResource ResourceKey=TFR_tbRating}" MaxTextLength="25"></local:usrValueSet>