我試圖將供應商提供的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