![](/img/trans.png)
[英]How do I access a TextBlock which is inside my ListBox's DataTemplate (but not Binding) in XAML?
[英]XAML How do I create a TextBlock responsive?
我有以下XAML代碼:
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Background="Transparent" Loaded="OnGridLoaded">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Foreground="{StaticResource CaptionColorBrush}" Text=">" />
<TextBlock Grid.Column="1" Background="Transparent" Style="{StaticResource BreadCrumsTextBlock}"
FontWeight="{Binding IsLastElement, Converter={StaticResource LastElementToFontWeightConverter}}"
Text="{Binding Title}" Margin="5 0 0 0" TextTrimming="CharacterEllipsis" />
<i:Interaction.Triggers>
<i:EventTrigger EventName="PreviewMouseLeftButtonDown">
<command:EventToCommand Command="{Binding Mode=OneWay, Path=DataContext.ReturnToFolderCommand, ElementName=ChannelsTab}" CommandParameter="{Binding NodeId}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
我想讓TextBlock
顯示所有發送的文本。 例如,如果我調整大小(擴展),它將僅顯示第一次發送的文本(假設屏幕已還原)。 誰能幫我解決問題?
包含Title的類必須實現INotifyPropertyChanged您的類需要看起來像這樣:
public class Model : INotifyPropertyChanged
{
//This is all that the interface requires
public event PropertyChangedEventHandler PropertyChanged;
private string _title;
public string Title
{
get { return _title; }
set
{
_text = value;
if(PropertyChanged != null)
PropertyChange(this, new PropertyChangedEventArgs("Title"));
}
}
}
如果這是一個復雜的項目,我建議您使用MVVM-Light http://www.mvvmlight.net/之類的MVVM框架,我過去曾將其用於Xamarin開發。 但是,還有許多其他選擇。
MVVM的優點之一是,您可以將XAML(GUI)與源代碼完全分離。 我通常使用單獨的項目來包含MVVM和XAML。 然后,您可以創建單元測試以練習MVVM。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.