0
當我將一個圖標按鈕添加到應用程序欄時,如果正在使用深色主題,則系統負責顯示白色圖標,如果正在使用燈光主題,則顯示黑色圖標。我可以在我的應用程序的其他地方使用自動着色嗎我想從SDK目錄中獲取圖標圖像並在正常按鈕上使用它,如果根據主題讓系統顯示白色或黑色,那將非常棒。現在我正在使用轉換器手動執行此操作,但如果有辦法自動執行此操作,則會更清晰。有誰知道一種方式?WP7中自動圖標着色的應用欄樣式?
當我將一個圖標按鈕添加到應用程序欄時,如果正在使用深色主題,則系統負責顯示白色圖標,如果正在使用燈光主題,則顯示黑色圖標。我可以在我的應用程序的其他地方使用自動着色嗎我想從SDK目錄中獲取圖標圖像並在正常按鈕上使用它,如果根據主題讓系統顯示白色或黑色,那將非常棒。現在我正在使用轉換器手動執行此操作,但如果有辦法自動執行此操作,則會更清晰。有誰知道一種方式?WP7中自動圖標着色的應用欄樣式?
<Button Background="{StaticResource PhoneContrastBackgroundBrush}" >
<Button.OpacityMask>
<ImageBrush ImageSource="/Images/icon.png"/>
</Button.OpacityMask>
</Button>
的icon.png必須是白色
[編輯]
OR(繪製他們周圍的圓),使用SDK圖像(appbar.basecircle.rest.png)
<Style x:Key="FlatStyle" TargetType="Button">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="Foreground" Value="{StaticResource PhoneForegroundBrush}"/>
<Setter Property="BorderThickness" Value="{StaticResource PhoneBorderThickness}"/>
<Setter Property="FontFamily" Value="{StaticResource PhoneFontFamilySemiBold}"/>
<Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMediumLarge}"/>
<Setter Property="Padding" Value="10,3,10,5"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Background="Transparent">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneDisabledBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="Transparent"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="ButtonBackground" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="0" Margin="{StaticResource PhoneTouchTargetOverhang}">
<Grid>
<Canvas Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
<Rectangle Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Fill="{StaticResource PhoneForegroundBrush}">
<Rectangle.OpacityMask>
<ImageBrush ImageSource="/appbar.basecircle.rest.png"/>
</Rectangle.OpacityMask>
</Rectangle>
<Rectangle Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" Fill="{StaticResource PhoneForegroundBrush}" OpacityMask="{TemplateBinding BorderBrush}"/>
</Canvas>
<ContentControl x:Name="ContentContainer" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" Foreground="{TemplateBinding Foreground}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
用法:
<Button Style="{StaticResource FlatStyle}" BorderThickness="0" Width="48" Height="48">
<Button.BorderBrush>
<ImageBrush ImageSource="/appbar.favs.rest.png"/>
</Button.BorderBrush>
</Button>
太棒了,謝謝。任何想法如何能夠在使用這種技術的同時將2張圖像層疊在一起?我正在使用SDK附帶的檢查和取消圖像,我想圍繞它們繪製一個圓圈(使用SDK附帶的圓形圖像)。 – Zik 2012-02-27 04:08:55
處理每個圖像的「可見」屬性 – Ku6opr 2012-02-27 08:16:15
您必須聲明按鈕樣式並使用它們。請參閱我的帖子更改 – ebattulga 2012-02-27 09:14:30