我正在WPF應用程序。我使用xml文件設置了多語言,並在前面的代碼中使用靜態資源綁定來設置相應的文本。我的問題是在代碼隱藏中做同樣的事情。XMLDataprovider標籤綁定代碼隱藏WPF c#
在這裏你可以看到我是如何使用它在前面代碼:
<XmlDataProvider x:Key="Lang" Source="/lng/english.xml" XPath="WpfApplication"/>
<Label HorizontalAlignment="Center" Margin="0,10,0,5" Foreground="White" FontWeight="Bold" Content="{Binding Source={StaticResource Lang}, XPath=MenuTextClimate/@Header}"></Label>
我試圖做同樣的代碼隱藏這樣的:
String selLangFullPath = WpfLibrary.LanguageOptions.getSelLangFullPath();
XmlDataProvider xmlData = (XmlDataProvider)(this.FindResource("Lang"));
xmlData.Source = new Uri(selLangFullPath, UriKind.Relative);
xmlData.XPath = "MenuTextClimate/@Header";
Binding NewBinding = new Binding();
NewBinding.Source = xmlData;
NewBinding.Mode = BindingMode.OneWay;
NewBinding.XPath = "MenuTextClimate";
lblTitle.SetBinding(Label.ContentProperty, NewBinding);
,但由於某種原因,它doesent似乎工作。任何人都可以告訴我我錯了哪裏?
謝謝先進。
感謝你這樣寫: – 2010-11-07 22:26:02
Label NewLabel1 = new Label(); Binding NewBinding = new Binding(); NewBinding.Source = xmlData; NewBinding.XPath = Description [i] .ToString(); NewLabel1.SetBinding(Label.ContentProperty,NewBinding); – 2010-11-07 22:26:51