我正在嘗試向我的 WPF 應用程式添加過濾,所以我想我想要一個橢圓,在它里面將是一個 TextBox,它的 Text 將系結到FilterText我的ViewModel.
我嘗試過的:
<TextBox
Width="30"
Height="30">
<TextBox.Template>
<ControlTemplate>
<Grid>
<Ellipse Stroke="Black" StrokeThickness="1" />
<ContentPresenter
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{Binding FilterText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextElement.Foreground="Black" />
</Grid>
</ControlTemplate>
</TextBox.Template>
</TextBox>
我從同一個例子中得到了這個,但使用了標簽。
這將顯示橢圓,但其中沒有 TextBox。
如何使用文本框創建橢圓?
uj5u.com熱心網友回復:
嘗試這個
<Grid>
<Ellipse Stroke="Black" StrokeThickness="1"/>
<TextBox Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}"
VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
uj5u.com熱心網友回復:
通過包裝TextBox內部 aBorder并設定Border's 來修復它CornerRadius:
<Border
Width="30"
Height="30"
BorderBrush="Black"
BorderThickness="1"
CornerRadius="30">
<TextBox
HorizontalAlignment="Center"
VerticalAlignment="Center"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Background="Transparent" //important to lose the TextBox look
BorderBrush="Transparent" //important to lose the TextBox look
BorderThickness="0" //important to lose the TextBox look
Text="{Binding FilterText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Border>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/360009.html
