0
我創建了一個CParametres在我app.xaml.cs這樣的對象:現在如何綁定屬性ApplicationRessource位於App.xaml中
public partial class App : Application
{
public CParametres myParamObject;
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
myParamObject = new CParametres(System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName) [email protected]"\BingMapsParam.ini");
if (myParamObject.LoadParams() == false)
{
return;
}
Resources.Add("myParamObject", myParamObject);
}
}
,在我的App.xaml,我添加Dictionnary:
<Application x:Class="myGeoloc.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="MyDictionary.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
而且,這裏是我的Dictionnary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:t="clr-namespace:myGeoloc"
xmlns:m="clr-namespace:Microsoft.Maps.MapControl.WPF;assembly=Microsoft.Maps.MapControl.WPF">
<t:CParametres x:Key="myParamObject"/>
<Style TargetType="m:Pushpin" x:Key="PushpinStyle_Fournisseur">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="m:Pushpin" >
<!-- <Image Stretch="Fill" Source="C:\Users\FabioWalter\Documents\Visual Studio 2013\Projects\myGeoloc\myGeoloc\bin\Debug\Pushpins\PushPinStandard.png" />-->
<Image Stretch="Fill" Source="{Binding Path=strPicturePushpinFournisseur, Source={StaticResource myParamObject}}" />
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Width" Value="64" />
<Setter Property="Height" Value="64" />
</Style>
</ResourceDictionary>
strPicturePushpinFournisseur是CParametres字符串。該字符串包含圖片路徑。
其實,圖像不顯示,它與我的壞綁定有關。
任何人都可以幫助我嗎? 任何想法?
感謝很多:)
感謝,以及如何定義「T:」爲CParametres對象 –
噸是名字空間,如果你正在使用Visual Studio它會自動完成... –
一看便知更新,t的命名空間被添加 –