我想到了一個想法,它簡短地解釋說我想加載xaml-files運行時,然後將它們綁定到運行時數據。 內這些XAML的文件,我會用一個叫做「PropertySetter」這樣的成分:綁定到運行時加載的XAML
public class PropertySetter : UserControl
{
public string Value { get; set; }
public string Text { get; set; }
public string Adress { get; set; }
public PropertySetter()
{
}
}
而且xamlfile,應該是這樣的:
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vf="clr-namespace:VisualFactory.vfGraphics.Graphics;assembly=VisualFactory">
<vf:PropertySetter Name="Datapoint" Text="propset" Value="false" Adress="10201" />
<CheckBox IsChecked="{Binding ElementName=Datapoint, Path=Value}" Content="{Binding ElementName=Datapoint, Path=Text}" />
</Grid>
我希望你現在明白了吧。 該複選框會將其值(內容,缺陷)綁定到屬性設置器,並且當應用程序運行時,它只會更改一堆「PropertySetter」的值,圖形將更新其內容和值。 但是:雖然xaml在加載時正確設置了值,但當我更改propertysetters的值時,它並不更新它們。我嘗試過設置Mode = TwoWay,而物業公司則位於iNotify集合中。 有沒有人嘗試過這樣的事情?
嗨AbdouThank的答案,但我已經嘗試過一個無果:) – Filip
但我在這裏找到答案:http://www.wpftutorial.net/DependencyProperties.html#creation 我只需要使用propertysetter類中的DependencyProperty。 – Filip
哦!是的,那將是我的第一個迴應,而且確實是這個問題,因爲你在XAML中設置了值,但是然後我讀了這個問題並忘記了這一點,只看到你沒有做更改通知。不過,我確定爲什麼你需要在XAML中創建'PropertySetter'(我還打算添加該註釋) – AbdouMoumen