English 中文(简体)
加入《刑法》
原标题:Binding to XMLDataProvider in Code Behind

i 存在一个问题,将XMLDataprovider与XPath从Xaml转移到代码后面。

Labels.xml

<?xml version="1.0" encoding="utf-8" ?>
<Labels>
  <btnOne Label="Button1"/>
  <btnTwo Label="Button2"/>
</Labels>

MainWindow.xaml

<Window
        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" mc:Ignorable="d" x:Class="bindings.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Window.Resources>
        <XmlDataProvider x:Key="XMLLabels" Source="Labels.xml" XPath="Labels"/>
    </Window.Resources>
    <Grid>
        <Button Content="{Binding Source={StaticResource XMLLabels}, XPath=btnOne/@Label}" Height="23" HorizontalAlignment="Left" Margin="12,12,0,276" Name="btnOne" Width="75" />
        <Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="93,12,0,276" Name="btnTwo" Width="75" Loaded="btnTwo_Loaded" />       
    </Grid>
</Window> 

MainWindow.xaml.cs

...
private void btnTwo_Loaded(object sender, RoutedEventArgs e)
{
    String Type = sender.GetType().Name;
    if (Type == "Button")
    {
        Button btn = sender as Button;
        Binding label = new Binding("XMLBind");
        XmlDataProvider xmlLabels = (XmlDataProvider)this.FindResource("XMLLabels");
        label.Source = xmlLabels;
        label.XPath = "btnTwo/@Header";
        btn.SetBinding(Button.ContentProperty, label);
    }
}
...

2. 装饰 “Button1”类作品。 但是,伤口是空洞的。 产出没有错误。

感谢任何建议。

最佳回答

la页: 1l.XPath = "btnTwo/@Header";

页: 1

la页: 1l.XPath = "btnTwo/@La页: 1l";
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签