Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - FocusVisualStyle

 
 
Old 02-08-2006   #1 (permalink)
joe_bloggs


 
 

FocusVisualStyle

I was expecting this xaml to change the style of the button with the focus

<Grid>
<Grid.Resources>
<Style x:Key="focusedButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="Yellow" />
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>

<Button Grid.Row="0" FocusVisualStyle="{StaticResource focusedButton}"
Content="Test1" />
<Button Grid.Row="1" FocusVisualStyle="{StaticResource focusedButton}"
Content="Test2" />
</Grid>

But it has no effect.
Could someone enlighten me.
Is it that the FocusVisualStyle require content not just setters on
properties?

Thanks

My System SpecsSystem Spec
Old 02-08-2006   #2 (permalink)
Bai Shi


 
 

RE: FocusVisualStyle

You should create a focusvisualstyle instead of restyling the button.
Try this:
<StackPanel
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
<Grid>
<Grid.Resources>
<Style x:Key="focusedButton">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Rectangle StrokeThickness="2" Stroke="Red"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>

<Button Grid.Row="0" FocusVisualStyle="{StaticResource focusedButton}"
Content="Test1" />
<Button Grid.Row="1" FocusVisualStyle="{StaticResource focusedButton}"
Content="Test2" />
</Grid>

</StackPanel>


"joe_bloggs" wrote:

> I was expecting this xaml to change the style of the button with the focus
>
> <Grid>
> <Grid.Resources>
> <Style x:Key="focusedButton" TargetType="{x:Type Button}">
> <Setter Property="Background" Value="Yellow" />
> </Style>
> </Grid.Resources>
> <Grid.RowDefinitions>
> <RowDefinition Height="Auto"></RowDefinition>
> <RowDefinition Height="Auto"></RowDefinition>
> </Grid.RowDefinitions>
>
> <Button Grid.Row="0" FocusVisualStyle="{StaticResource focusedButton}"
> Content="Test1" />
> <Button Grid.Row="1" FocusVisualStyle="{StaticResource focusedButton}"
> Content="Test2" />
> </Grid>
>
> But it has no effect.
> Could someone enlighten me.
> Is it that the FocusVisualStyle require content not just setters on
> properties?
>
> Thanks

My System SpecsSystem Spec
Old 02-09-2006   #3 (permalink)
Bai Shi


 
 

RE: FocusVisualStyle

Basically, the idea of FocusVisualStyle is to add an AdornerLayer on top of
the control. So the ContentTemplate of FocusVisualStyle won't merge with the
control's template.

Bai Shi

"joe_bloggs" wrote:

> Thanks for the reply.
>
> How is the ContentTemplate applied to the control that it is applied to?
>
> The ContentTemplate does not replace the content of the control it is
> applied to, so how is it combined?
>
> Thanks
>
>
>
>
> "Bai Shi" wrote:
>
> > You should create a focusvisualstyle instead of restyling the button.
> > Try this:
> > <StackPanel
> > xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
> > xmlns:sys="clr-namespace:System;assembly=mscorlib"
> > xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
> > <Grid>
> > <Grid.Resources>
> > <Style x:Key="focusedButton">
> > <Setter Property="Control.Template">
> > <Setter.Value>
> > <ControlTemplate>
> > <Rectangle StrokeThickness="2" Stroke="Red"/>
> > </ControlTemplate>
> > </Setter.Value>
> > </Setter>
> > </Style>
> > </Grid.Resources>
> > <Grid.RowDefinitions>
> > <RowDefinition Height="Auto"></RowDefinition>
> > <RowDefinition Height="Auto"></RowDefinition>
> > </Grid.RowDefinitions>
> >
> > <Button Grid.Row="0" FocusVisualStyle="{StaticResource focusedButton}"
> > Content="Test1" />
> > <Button Grid.Row="1" FocusVisualStyle="{StaticResource focusedButton}"
> > Content="Test2" />
> > </Grid>
> >
> > </StackPanel>
> >
> >
> > "joe_bloggs" wrote:
> >
> > > I was expecting this xaml to change the style of the button with the focus
> > >
> > > <Grid>
> > > <Grid.Resources>
> > > <Style x:Key="focusedButton" TargetType="{x:Type Button}">
> > > <Setter Property="Background" Value="Yellow" />
> > > </Style>
> > > </Grid.Resources>
> > > <Grid.RowDefinitions>
> > > <RowDefinition Height="Auto"></RowDefinition>
> > > <RowDefinition Height="Auto"></RowDefinition>
> > > </Grid.RowDefinitions>
> > >
> > > <Button Grid.Row="0" FocusVisualStyle="{StaticResource focusedButton}"
> > > Content="Test1" />
> > > <Button Grid.Row="1" FocusVisualStyle="{StaticResource focusedButton}"
> > > Content="Test2" />
> > > </Grid>
> > >
> > > But it has no effect.
> > > Could someone enlighten me.
> > > Is it that the FocusVisualStyle require content not just setters on
> > > properties?
> > >
> > > Thanks

My System SpecsSystem Spec
 

Thread Tools



Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46