我试图将供应商提供的VB解决方案转换为C#
。我需要从一个自定义的ResourceDictionary XAML
加载一个DataTemplate到一个c#
类。我无法确定如何获取DataTemplate。我能够创建一个ResourceDictionary并加载XAML
但我从那里难倒了。这是我的XAML
[EditorResources]。从代码背后的ResourceDictionary中访问DataTemplate
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:PropertyEditing="clr-namespace:Microsoft.Windows.Design.PropertyEditing;assembly=Microsoft.Windows.Design.Interaction"
xmlns:Local="clr-namespace:MyControls.Design"
xmlns:my="clr-namespace:MyControls;assembly=MyControls"
x:Class="EditorResources">
<DataTemplate x:Key="TagBrowserInlineEditorTemplate">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding StringValue}"/>
<PropertyEditing:EditModeSwitchButton Grid.Column="1"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="template">
<Border BorderThickness="2"
BorderBrush="Black">
<TextBlock Text="{Binding Path=value}" Padding="2" />
</Border>
</DataTemplate>
</ResourceDictionary>
这里是VB代码,我需要转换:
Imports System
Imports System.ComponentModel
Imports System.Windows
Imports Microsoft.Windows.Design.Metadata
Imports Microsoft.Windows.Design.PropertyEditing
Imports Microsoft.Win32
Public Class TagBrowserDialogPropertyValueEditor
Inherits DialogPropertyValueEditor
Private res As New EditorResources()
Public Sub New()
Me.InlineEditorTemplate = TryCast(res("TagBrowserInlineEditorTemplate"), DataTemplate)
End Sub
Public Overloads Overrides Sub ShowDialog(ByVal propertyValue As PropertyValue, ByVal commandSource As IInputElement)
Dim frmBrowseTagParameter As New OPCWPFDashboard.Design.FormBrowseTagParameter
If frmBrowseTagParameter Is Nothing Then
frmBrowseTagParameter = New OPCWPFDashboard.Design.FormBrowseTagParameter
End If
If frmBrowseTagParameter.ShowDialog = Forms.DialogResult.OK Then
propertyValue.StringValue = frmBrowseTagParameter.Final_Tag
End If
End Sub
End Class
谢谢。这正是我想要做的。 – Schrecengost
很高兴为您服务!请将答案标记为已接受。 – Pavel