我有一個簡單的UserControl,我想將Label文本值綁定到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>
我改變了我的財產是非靜態的。將綁定更改爲{Binding Path =(local:Application.TestVal)}。但是,我收到錯誤。 「解析XAML時出錯,無法將屬性路徑中的字符串'(local:Application.TestVal)}'轉換爲System.Windows.PropertyPath類型的對象,屬性路徑無效 – CathalMF 2014-09-25 16:00:12
這是否是確切的錯誤信息?在你的綁定路徑中有一個流浪的'}' – 2014-09-25 16:57:12
是的,這是確切的錯誤。沒有流浪} – CathalMF 2014-09-30 09:43:52