开发者

how to set the color of toggle button from style already defined in app xaml?

I had created a button and i want to change its color using style from app xaml. But,i don't get the exact code and i am new to xaml.

Can any one he开发者_运维问答lp me with some example.

I am also confused to use which property to change color means background or foreground?


<Window
  x:Class="ToolBar"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="ToolBar"
  Width="300"
  Height="300">
  <DockPanel>
    <ToolBarTray
      DockPanel.Dock="Top"
      IsLocked="True"
      Orientation="Horizontal">
      <ToolBar
        x:Name="ToolBar1">
        <ToggleButton>
          <ToggleButton.Style>
            <Style
              TargetType="{x:Type ToggleButton}">
              <Setter Property="ContentTemplate">
                <Setter.Value>
                  <DataTemplate>
                    <Label>Play</Label>
                  </DataTemplate>
                </Setter.Value>
              </Setter>
              <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                  <Setter Property="ContentTemplate">
                    <Setter.Value>
                      <DataTemplate>
                        <Label>Pause</Label>
                      </DataTemplate>
                    </Setter.Value>
                  </Setter>
                  <Setter Property="BorderBrush" Value="Transparent" />
                  <Setter Property="Panel.Background" Value="Transparent" />
                </Trigger>
              </Style.Triggers>
            </Style>
          </ToggleButton.Style>
        </ToggleButton>
      </ToolBar>
    </ToolBarTray>
  </DockPanel>
</Window>

Within a toolbar, the two statements:

<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Panel.Background" Value="Transparent" />

causes the toggle button to appear in the normal state when the toggle button is checked, however nothing changes when you hover over the checked toggle button.

If I wrap the toggle button in another layout, say wrap layout:

<Window
  x:Class="ToolBar"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="ToolBar"
  Width="300"
  Height="300">
  <WrapPanel>
        <ToggleButton>
          <ToggleButton.Style>
            <Style
              TargetType="{x:Type ToggleButton}">
              <Setter Property="ContentTemplate">
                <Setter.Value>
                  <DataTemplate>
                    <Label>Play</Label>
                  </DataTemplate>
                </Setter.Value>
              </Setter>
              <Style.Triggers>
                <Trigger Property="IsChecked" Value="True">
                  <Setter Property="ContentTemplate">
                    <Setter.Value>
                      <DataTemplate>
                        <Label>Pause</Label>
                      </DataTemplate>
                    </Setter.Value>
                  </Setter>
                  <Setter Property="BorderBrush" Value="Transparent" />
                  <Setter Property="Panel.Background" Value="Transparent" />
                </Trigger>
              </Style.Triggers>
            </Style>
          </ToggleButton.Style>
        </ToggleButton>
  </WrapPanel>
</Window>

the two statements:

<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Panel.Background" Value="Transparent" />

You can find tutorial in the folowing url http://social.msdn.microsoft.com/Forums/pl-PL/wpf/thread/7e565a41-0aad-40a3-a3c4-666c5caf38fe

Thanks Deepak

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜