button有很多和wpf一樣,可以看《深入淺出WPF》
我們可以在button的click寫上
~~~
<Button Content="確定" Click="Button_Click"/>
~~~
在Button_Click按F12到代碼寫上點擊按鈕需要運行
~~~
private void Button_Click(object sender, RoutedEventArgs e)
{
}
~~~
也可以用viewModel的一個方法 viewModel有一個方法 ce
可以在Click寫
~~~
Click="{x:Bind view.ce}"
~~~
在用view需要在MainPage.xaml.cs寫
~~~
viewModel view {set;get;}= new viewModel();
~~~
button content可以使用一個元素,這個元素可以是Grid,我們可以做一個圓形頭像
先找出一張圖,我們把這張圖做頭像
把圖放到項目
~~~
<Button Height="100" Width="100" Margin="10,10,10,10" Padding="0" Foreground="{x:Null}" BorderBrush="{x:Null}" Background="{x:Null}">
<Button.Content>
<Ellipse Margin="0,0,0,0" Height="90" Width="90">
<Ellipse.Fill>
<ImageBrush ImageSource="Assets/20151226160608688.jpg" />
</Ellipse.Fill>
</Ellipse>
</Button.Content>
</Button>
~~~
我們可以修改鼠標在按鈕上的樣子
button可以設置屬性,使用資源 資源可以寫在頁面
~~~
<Page.Resources>
</Page.Resources>
~~~
所有按鈕使用同樣式
~~~
<Page.Resources>
<Style TargetType="Button">
</Style>
</Page.Resources>
~~~
按鈕的屬性用`<Setter Property="屬性" Value="值"/>`
按鈕的背景
~~~
<Page.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="White"/>
</Style>
</Page.Resources>
~~~
指定一個樣式,key
~~~
<Page.Resources>
<Style TargetType="Button">
<Setter Property="Background" Value="White"/>
<Setter Property="Width" Value="100"/>
<Setter Property="Height" Value="100"/>
</Style>
<Style x:Key="button" TargetType="Button">
<Setter Property="Background" Value="White"/>
<Setter Property="Width" Value="50"/>
<Setter Property="Height" Value="50"/>
</Style>
</Page.Resources>
~~~
~~~
<Button Content="默認"/>
<Button Style="{StaticResource button}" Content="確定"/>
~~~

在設計,點按鈕,右擊,編輯模板副本,選擇當前頁
可以看到
~~~
<Page.Resources>
<Style x:Key="ButtonStyle1" TargetType="Button">
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}"/>
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}"/>
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundTransparentBrush}"/>
<Setter Property="BorderThickness" Value="{ThemeResource ButtonBorderThemeThickness}"/>
<Setter Property="Padding" Value="8,4,8,4"/>
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
<Setter Property="UseSystemFocusVisuals" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid x:Name="RootGrid" Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="RootGrid"/>
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseMediumLowBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseHighBrush}"/>
</ObjectAnimationUsingKeyFrames>
<PointerUpThemeAnimation Storyboard.TargetName="RootGrid"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="RootGrid">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseMediumLowBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightTransparentBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlHighlightBaseHighBrush}"/>
</ObjectAnimationUsingKeyFrames>
<PointerDownThemeAnimation Storyboard.TargetName="RootGrid"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="RootGrid">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlBackgroundBaseLowBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledBaseLowBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ContentPresenter">
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource SystemControlDisabledTransparentBrush}"/>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<ContentPresenter x:Name="ContentPresenter" AutomationProperties.AccessibilityView="Raw" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentTransitions="{TemplateBinding ContentTransitions}" Content="{TemplateBinding Content}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>
~~~
在`<VisualState x:Name="Pressed">`可以把里面寫成這個狀態的樣子,按鈕有正常,按下,鼠標在按鈕上,可以對每個修改

點擊Pressed更改pressed
看到這里按鈕有背景
去掉背景,按F4把背景無畫筆
添加過度
記錄關鍵幀
選時間0.5改變背景
選時間,改變背景
點播放可以看到我們做出來的
可以運行
移動到button顯示文字
在裝機必備移動到搜狐顯示搜狐 參考:[http://blog.csdn.net/lindexi_gd/article/details/50166161](http://blog.csdn.net/lindexi_gd/article/details/50166161)
~~~
<Button Click="souhu_Click" ToolTipService.ToolTip="搜狐視頻" Padding="0" >
<Button.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Image Source="ms-appx:///Assets/搜狐.png" Grid.Row="0" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
<TextBlock Text="搜狐視頻" Grid.Row="1" HorizontalAlignment="Center" />
</Grid>
</Button.Content>
</Button>
~~~

顯示圖片
~~~
<Button Click="souhu_Click" Padding="0" >
<Button.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<Image Source="ms-appx:///Assets/搜狐.png" Grid.Row="0" ScrollViewer.VerticalScrollBarVisibility="Disabled" />
<TextBlock Text="搜狐視頻" Grid.Row="1" HorizontalAlignment="Center" />
</Grid>
</Button.Content>
<ToolTipService.ToolTip>
<Image Height="50" Width="50" Source="ms-appx:///Assets/搜狐.png"/>
</ToolTipService.ToolTip>
</Button>
~~~
- 前言
- UWP win10 app 新關鍵字x:Bing
- win10應用 UWP 使用MD5算法
- win10 UWP讀寫文件
- UWP appButtonBar樣式
- C# 6.0 $&quot;Hello {csdn}&quot;
- Win10 UWP xaml 延遲加載元素
- UWP xaml 圓形頭像
- UWP 繪制圖形
- win10 uwp 通知Toast
- win10 UWP 顯示地圖
- win10 uwp 參考
- win10 uwp clone
- win10 uwp 裝機必備應用 含源代碼
- RichEditBox 使用自定義菜單
- win10 UWP FlipView
- win10 UWP 獲取系統信息
- win10 UWP 申請微軟開發者
- win10 UWP button
- win10 UWP Markdown 含源代碼
- win10 UWP 應用設置
- win10 UWP 九幽數據分析
- win10 UWP 圓形等待
- win10 UWP 標題欄后退
- win10 UWP 單元測試
- win10 UWP 你寫我讀
- win10 UWP RSS閱讀器
- win10 UWP MessageDialog 和 ContentDialog
- win10 UWP Hmac
- win10 UWP GET Post
- Win10 UWP Intro to controls and events
- win10 UWP Controls by function
- win10 uwp App-to-app communication 應用通信