0
我一直在編寫一些類,這些類將用在窗口的XAML定義中。我記得使用一個稱爲 - AFAIR - ConstructorParameter的屬性,它通知XAML解析器,與此屬性相對應的某些XML屬性應視爲構造函數參數而不是屬性設置器。C#/ ConstructorParameter屬性
我已經在互聯網上來回搜索,找不到該屬性屬於哪個程序集。誰能幫忙?
此致敬禮 - Spook。
我一直在編寫一些類,這些類將用在窗口的XAML定義中。我記得使用一個稱爲 - AFAIR - ConstructorParameter的屬性,它通知XAML解析器,與此屬性相對應的某些XML屬性應視爲構造函數參數而不是屬性設置器。C#/ ConstructorParameter屬性
我已經在互聯網上來回搜索,找不到該屬性屬於哪個程序集。誰能幫忙?
此致敬禮 - Spook。
通常你會想要一個默認的構造函數和一個屬性來獲得額外的值。
我在wpfwiki上找到了this article。 ...
典型的XAML聲明語法 最終總是使用 其默認的構造函數創建對象。大部分是 的時間,這不是問題。然而, 某些類具有構造函數,其中某些參數取值爲 ,或者根本沒有 具有默認構造函數。在這些 的情況下,仍然可以使用ObjectDataProvider類在XAML中聲明 。以下 銷售點系統代碼 代碼段在 Window.Resources部分顯示此類聲明。
<Window x:Class="WindowsApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System"
Title="ObjectDataProvider Sample"
Height="300"
Width="300"
>
<Window.Resources>
<ObjectDataProvider ObjectType="{x:Type CornerRadius}"
x:Key="MyCornerRadius">
<ObjectDataProvider.ConstructorParameters>
<system:Double>10.5</system:Double>
</ObjectDataProvider.ConstructorParameters>
</ObjectDataProvider>
</Window.Resources>
<Grid>
<TextBlock Text="{Binding Source={StaticResource MyCornerRadius}, Path=TopLeft}"/>
</Grid>
</Window>
我發現了我正在搜索的屬性,它是ConstructorArgument。然而,我很快意識到,這個id並沒有做到我所猜測的那樣,而且無論如何我將實現無參數的構造函數 - 正如你所提到的那樣。感謝幫助! – Spook 2011-04-07 06:18:38