![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Button with regular image and disabled image I am trying to make a button in xaml with different images when enabled and disabled. I tried using a Trigger on IsEnabled, but when I tried to set the Content to an image, I got an exception 'System.Windows.Controls.Image' value not valid for property 'Content'. 'Setter' does not support values derived from Visual or ContentElement. The XAML is this <Style x:Key="undoStyle" TargetType="{x:Type Button}"> <Style.Triggers> <Trigger Property="IsEnabled" Value="True"> <Setter Property="Content"> <Setter.Value> <Image Source="Images/Undo.png" /> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="Content"> <Setter.Value> <Image Source="Images/Undo-Disabled.png" /> </Setter.Value> </Setter> </Trigger> </Style.Triggers> </Style> I started down the road of using a DataTemplate to style an object (was going to use an XML data island). Haven't gotten that to work, but this all seems pretty complicated for such a simple thing. I am about to do it in C#, but in case I'm missing something obvious, I thought I'd ask. |
My System Specs![]() |
| | #2 (permalink) |
| | RE: Button with regular image and disabled image Hi, Attempting to set a button's content to a Visual or ContentElement in a Style will result in the error you note -- Styles can be shared, whereas the Visual/ContentElement you are trying to put inside it can not be shared. Let me know if you would like further explanation on this. To accomplish what I think you are trying to do here, you could use a DataTemplate to set your Button's ContentTemplate as follows (using XAML): <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Page.Resources> <Style TargetType="{x:Type Button}"> <Setter Property="HorizontalAlignment" Value="Center"/> <Setter Property="ContentTemplate"> <Setter.Value> <DataTemplate> <Image Source="go.png" Width="100" x:Name="theImage"/> <DataTemplate.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Button}}, Path=IsEnabled}" Value="False"> <Setter TargetName="theImage" Property="Source" Value="disable.png"/> </DataTrigger> </DataTemplate.Triggers> </DataTemplate> </Setter.Value> </Setter> </Style> </Page.Resources> <StackPanel> <Button IsEnabled="False"/> <Button /> </StackPanel> </Page> -Shalini ---------- "loumfranco@gmail.com" wrote: > I am trying to make a button in xaml with different images when enabled > and disabled. I tried using a Trigger on IsEnabled, but when I tried > to set the Content to an image, I got an exception > > 'System.Windows.Controls.Image' value not valid for property 'Content'. > 'Setter' does not support values derived from Visual or ContentElement. > > The XAML is this > > <Style x:Key="undoStyle" TargetType="{x:Type Button}"> > <Style.Triggers> > <Trigger Property="IsEnabled" Value="True"> > <Setter Property="Content"> > <Setter.Value> > <Image Source="Images/Undo.png" /> > </Setter.Value> > </Setter> > </Trigger> > <Trigger Property="IsEnabled" Value="False"> > <Setter Property="Content"> > <Setter.Value> > <Image Source="Images/Undo-Disabled.png" /> > </Setter.Value> > </Setter> > </Trigger> > </Style.Triggers> > </Style> > > > I started down the road of using a DataTemplate to style an object (was > going to use an XML data island). Haven't gotten that to work, but > this all seems pretty complicated for such a simple thing. I am about > to do it in C#, but in case I'm missing something obvious, I thought > I'd ask. > > |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Datagrid Image Button Select Column | .NET General | |||
| Various Errors - winlogon.exe Bad Image, Windows - Bad Image & Window Defender | General Discussion | |||
| Acronis True Image recovery of Vista Image | Vista General | |||