wpf 改 UI一些技巧

本人WPF入门级,所以目前的经验也属于菜鸟级,高手请一笑而过

 

 1. 底部状态栏,左右有文本,中间空格随窗体大小变化

MarkUp:

 

<StatusBar Name="statusBar" Grid.Row="3"> <DockPanel></DockPanel> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Name="statusBarSpace" Width="*"/> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Grid.Column="0" Name="statusBarText1">Text1</TextBlock> <TextBlock Grid.Column="2" Name="statusBarText2" Text="Text2"></TextBlock> </Grid> </StatusBar>  

 

 

Code Block:

 

private void UserControl_SizeChanged(object sender, SizeChangedEventArgs e) { AdjustControls(); } private void AdjustControls() { // Adjust status bar double statusBarWidth = statusBar.ActualWidth; double control0width = statusBarText1.ActualWidth; double control2width = statusBarText2.ActualWidth; statusBarSpace.Width = new GridLength(statusBarWidth - (control0width + control2width) - 30, GridUnitType.Pixel); } 

 

参考资料:

 

http://forums.silverlight.net/forums/t/17692.aspx

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/1f82d834-efae-4eb3-819f-40c2168fb8c9

 

2. 制作flat(平坦)的按钮

需求:Button上有图片,不想看到button的框子

 

 

<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Grid.Row="0" Grid.Column="1" Background="Transparent" Height="30" Click="Button_Click"> <Grid> <Image Name="img" Source="../button.png"/> </Grid> </Button> 

 

 

要点:

WPF lets you completely restyle controls to make them look like whatever you want, which is why it doesn't have such a specific FlatStyle property on the Button control.

 

WPF 给你完全的自由去设定控件的样式。(接口太宽,初学者真是难下手啊)使用这个样式可以让按钮平坦。

<Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"/>

 

参考资料:

http://stackoverflow.com/questions/697381/setting-button-flatstyle-in-wpf

 

你可能感兴趣的:(c,UI,image,object,button,WPF)