Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
Windos
win32.3rdparty
win32.directx.audio
win32.directx.ddk
win32.directx.graphics
win32.directx.input
win32.directx.managed
win32.directx.misc
win32.directx.networking
win32.directx.sdk
win32.directx.video
win32.dirx.grap.shaders
win32.gdi
win32.international
win32.kernel
win32.messaging
win32.mmedia
win32.networks
win32.ole
win32.rtc
win32.tapi
win32.tapi.beta
win32.tools
win32.ui
win32.wince
win32.wmi
windows.mediacenter
winfx.aero
winfx.announcements
winfx.avalon
winfx.collaboration
winfx.fundamentals
winfx.general
winfx.indigo
winfx.sdk
winfx.winfs
  
 
date: Thu, 25 Oct 2007 05:48:28 -0700,    group: microsoft.public.windows.developer.winfx.avalon        back       


Using variable XPaths in Style declarations   
Hello,

I have this simple piece of XAML (just paste it into XAMLPad and it
will work).


<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/
presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

   <Canvas.Resources>

      <XmlDataProvider x:Key="DataProvider" XPath="Data">
         <x:XData>
            <Data xmlns="">
               <TB Name="TXT_1">
                  <Background>yellow</Background>
               </TB>
               <TB Name="TXT_2">
                  <Background>green</Background>
               </TB>
            </Data>
         </x:XData>
      </XmlDataProvider>

   </Canvas.Resources>

   <Canvas.DataContext>
      <Binding Source="{StaticResource DataProvider}" />
   </Canvas.DataContext>

   <TextBox x:Name="TXT_1" Canvas.Top="0" Height="20" Width="200">
        <TextBox.Background>
          <Binding XPath="TB[@Name='TXT_1']/Background" />
        </TextBox.Background>
   </TextBox>

   <TextBox x:Name="TXT_2" Canvas.Top="40" Height="20" Width="200">
        <TextBox.Background>
          <Binding XPath="TB[@Name='TXT_2']/Background" />
        </TextBox.Background>
   </TextBox>

</Canvas>


Now I looked at how my TextBoxes are declared and I thought to myself:
Well, any TextBox has the same bindings except from the XPath which is
the same apart from the name of the piece of the Xml that I actually
want to be my data source. But on the other hand the value of the
"variable part" in the XPath is always the name of my TextBox.
So I wondered whether I can make all the bindings be part of a style
for TextBoxes. This is what I tried:


<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/
presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

   <Canvas.Resources>

      <XmlDataProvider x:Key="DataProvider" XPath="Data">
         <x:XData>
            <Data xmlns="">
               <TB Name="TXT_1">
                  <Background>yellow</Background>
               </TB>
            </Data>
         </x:XData>
      </XmlDataProvider>

      <Style x:Key="txtStyle" TargetType="{x:Type TextBox}">
         <Setter Property="TextBox.Background">
            <Setter.Value>
               <SolidColorBrush Color="{Binding XPath=//TB[@Name\=
\'TXT_1\']/Background}" />
            </Setter.Value>
         </Setter>
      </Style>

   </Canvas.Resources>

   <Canvas.DataContext>
      <Binding Source="{StaticResource DataProvider}" />
   </Canvas.DataContext>

   <TextBox x:Name="TXT_1" Canvas.Top="0" Height="20" Width="200"
Style="{StaticResource txtStyle}" />

   <TextBox x:Name="TXT_2" Canvas.Top="40" Height="20" Width="200"
Style="{StaticResource txtStyle}" />

</Canvas>


Works fine, only that I now have a fixed name in the Binding statement
for the Background property. I do not know how to make this variable.
What I would like to have is something like

	<SolidColorBrush Color="{Binding XPath=//TB[@Name\={TemplateBinding
Name}]/Background}" />

Sorry for mixing templates in here, but I thought this would be the
best way to describe what I would like to achieve.

Any suggestions are highly welcome.

Thanks,
Michael
date: Thu, 25 Oct 2007 05:48:28 -0700   author:   unknown

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us