Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

xaml Listbox binding to Dataprovider

$
0
0

Hey i'm trying to make a rectangle that changes it's color to the selected color by the list , items are in a dataprovider i've made everything and tried to add binding to the rectangle but came up with a rectangle that doesn't change hope you guys find what's the problem

here is my code

<Window x:Class="dataBindingSimple.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"><Window.Resources><XmlDataProvider x:Key="XmlData" XPath="/colors">    <!--Who will provide with data and how you're going to recieve it--><x:XData xmlns=''>  <!--add xmlns="" to show listbox 2 in execution--> <colors Name="DemoColors">   <!--defining colors as objects --><color name="Black"></color><!--defining color peroperty name of your choice because object was created by us --><color name="Cyan"></color><color name="Magenta"></color></colors></x:XData></XmlDataProvider>        </Window.Resources><Grid DataContext="{Binding Source={StaticResource XmlData}}"><Rectangle Fill="{Binding SelectedItem, ElementName=lbColor}"
               HorizontalAlignment="Left"
               Height="76"
               Margin="11,233,0,0"
               Stroke="Black"
               VerticalAlignment="Top" 
               Width="162" /> <ListBox x:Name="lbColor"   HorizontalAlignment="Left" Height="118"                            Margin="376,32,0,0" VerticalAlignment="Top" Width="96" ItemsSource="{Binding Source=  {StaticResource XmlData},XPath=/colors/color/@name}"/> <!-- getting from itemSource --></Grid></Window>


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>