1
これがなぜ機能しないのかは誰にも分かります。 これは本当にシンプルですが、ListBoxは起動時に空です。コードの背後にはInitializeComponent()だけが含まれています。ListBoxをXmlDataProviderにバインドする
うまくいけば、誰かがアイデア... H.B @
<Window x:Class="DasDataGrid.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
Title="MainWindow" Height="350" Width="700">
<Window.Resources>
<XmlDataProvider x:Key="Maschinen" XPath="/machines">
<x:XData>
<machines>
<machine name="alte Maschine"/>
<machine name="neue Maschine"/>
</machines>
</x:XData>
</XmlDataProvider>
</Window.Resources>
<ListBox ItemsSource="{Binding Source={StaticResource Maschinen},XPath=machine/@name}"
IsSynchronizedWithCurrentItem="True"
SelectedIndex="1">
</ListBox>
</Window>
を持っています。 ここに私がテストしたコードがあります。それを起動すると、ListBoxはまだ空です。私は何が間違っているのか分からない。
あなたは空の文字列にするのxmlnsを設定する必要が<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<StackPanel>
<StackPanel.Resources>
<XmlDataProvider x:Key="Maschinen">
<x:XData>
<machines xmlns="">
<machine name="alte Maschine"/>
<machine name="neue Maschine"/>
</machines>
</x:XData>
</XmlDataProvider>
</StackPanel.Resources>
<ListBox ItemsSource="{Binding Source={StaticResource Maschinen}, XPath=machine}"
IsSynchronizedWithCurrentItem="True" DisplayMemberPath="@name"
SelectedIndex="1">
</ListBox>
</StackPanel>
</Window>
はありがとうございます。私はあなたのコードをテストしましたが、うまくいきません。 ListBoxはまだ空です。何か案は? – user1078325
私はこのことをテストしました。編集したコードを一時的に質問に追加できますか? –
私は何が間違っているのか分かりました:XPath =/machines/machine それはうまくいきます! ありがとう! – user1078325