【发布时间】:2014-11-20 11:12:44
【问题描述】:
我有一个简单的用户控件,我想在其中将标签文本值绑定到 DLL 中的属性。 我的主应用程序允许我通过指定 XAML 来插入我自己的用户控件。
在下面的 XAML 中,我使用的 CheckSubtotal 属性是加载用户控件的应用程序的一部分。此属性填充在控件中没有任何问题。 在下面的 XAML 中,TestValue 属性位于我在 XAML 开头指定的 MyTestDLL.dll 中。此属性未填充在控件中。
示例 DLL - MyTestDLL.dll
namespace MyTestNamespace
{
public class Application
{
public static string TestValue = "TestVal";
public Application()
{}
}
}
XAML 示例
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:systemWindows="clr-namespace:System.Windows;assembly=PresentationFramework"
xmlns:local="clr-namespace:MyTestNamespace;assembly=MyTestDLL"
>
<Grid>
<DockPanel>
<Border DockPanel.Dock="Left" Width="294" Margin="3,0,4,3" CornerRadius="0,0,3,3" Padding="2" BorderBrush="Black" BorderThickness="0" Background="White">
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" HorizontalAlignment="Stretch" Margin="5,0,5,0">
<Grid>
<Label FontSize="20" Content="SubTotal:" HorizontalAlignment="Left" Margin="10,0,0,0" Width="129.51"/>
<Label FontSize="20" HorizontalAlignment="Right" Margin="0,0,21,0" Content="{Binding Path=CheckSubtotal}"/>
</Grid>
<Grid>
<Label FontSize="20" Content="TestValue:" HorizontalAlignment="Left" Margin="10,0,0,0" Width="129.51"/>
<Label FontSize="20" HorizontalAlignment="Right" Margin="0,0,21,0" Content="{Binding Path=TestValue}"/>
</Grid>
</StackPanel>
</DockPanel>
</Border>
</DockPanel>
</Grid>
</UserControl>
【问题讨论】:
标签: c# wpf xaml namespaces