所以我有一個TextBox,我在我的Ressource Dictionary里做了這樣的Style:
<Style x: Key="TextBoxTemplateBrowser" TargetType="{x:Type TextBox}">/span>
< Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">/span>
<Setter.Value>/span>
<ControlTemplate TargetType="{x:Type TextBox}"/span>>
< Border Background="White"/span> CornerRadius="0 0 5 5" BorderBrush="Black" BorderThickness="1"/span>>
< ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Border>/span>
</ControlTemplate>/span>
</Setter.Value>/span>
</Setter>/span>
</Style>
而我的TextBox自己是這樣的:
< TextBox TextWrapping="Wrap"/span> x: Name="tb" Style="{DynamicResource TextBoxTemplateBrowser}"
Text="{Binding Inhalt, RelativeSource={RelativeSource AncestorType=local:ArtikelBezPanel}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
TextChanged="TextBox_TextChanged"
Height="{Binding Height, RelativeSource={RelativeSource AncestorType=local: ArtikelBezPanel}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" AcceptsReturn="True" BorderBrush="Black" AcceptsTab="True" VerticalAlignment="Top" BorderThickness="1">
</TextBox>/span>
我現在遇到的問題是,當我試圖在TextBox中寫東西時,我可以寫任何東西,但不能顯示我之前宣告的文本。
CodePudding
當模板化 TextBox 時,你需要 PART_ContentHost:eg:
< ScrollViewer Margin="0"/span> x: Name="PART_ContentHost" />
更多資訊請參見DOCS!
替換
< ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
與
< ScrollViewer Margin="0"/span> x: 名稱="PART_ContentHost" HorizontalAlignment="Center" VerticalAlignment="Center"/>
而且它應該能作業!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/307892.html
標籤:
上一篇:Oxyplot-隱藏中間軸的數值
下一篇:動態添加一個用戶控制元件
