0

usercontrol.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

usercontrol.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」を設定することはできません。「DynamicResourceExtension」は、DependencyObject の DependencyProperty でのみ設定できます。

上記のように..

動的リソースを 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 に答える