16
需要有平坦的邊框樣式基於WPF的文本框...真的驚訝地看到有沒有簡單的方法來得到這個就像是在WinForms的文本BorderStyle.FixedSingleWPF文本框平面的邊緣風格
有沒有什麼簡單的方法完成這件事的WPF文本框
需要有平坦的邊框樣式基於WPF的文本框...真的驚訝地看到有沒有簡單的方法來得到這個就像是在WinForms的文本BorderStyle.FixedSingleWPF文本框平面的邊緣風格
有沒有什麼簡單的方法完成這件事的WPF文本框
<TextBox BorderThickness="1" BorderBrush="Black">
只是黑色試試這個或灰色
做到這一點的方法是使用一個控制模板,自己繪製的邊界。你可以用許多不同的方式做到這一點,繼承人有幾個讓你看看。
快速破解方法:
<TextBox>
<TextBox.Template>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<Rectangle Stroke="{StaticResource ResourceKey=detailMarkBrush}" StrokeThickness="1"/>
<TextBox Margin="1" Text="{TemplateBinding Text}" BorderThickness="0"/>
</Grid>
</ControlTemplate>
</TextBox.Template>
</TextBox>
,然後使用資源那裏有...
<ResourceDictionary>
<Color x:Key="detailMark">#FFA1A9B3</Color>
<SolidColorBrush x:Key="detailMarkBrush" Color="{StaticResource ResourceKey=detailMark}" />
<Style x:Key="flatTextBox" TargetType="{x:Type TextBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<Rectangle Stroke="{StaticResource ResourceKey=detailMarkBrush}" StrokeThickness="1"/>
<TextBox Margin="1" Text="{TemplateBinding Text}" BorderThickness="0"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
,然後你可以使用風格:
<TextBox Style="{StaticResource ResourceKey=flatTextBox}" />
這似乎只工作而文本框不重點。當它獲得焦點時,邊框將突出顯示兩個藍色陰影。 – 2011-10-17 23:54:10