我正在使用下一個代碼來顯示ListView。 ListView控件包含具有結合到一個變量對我一個的MainPage一個FontSized的TextBlock:列表視圖中的Metro XAML綁定
<ListView x:Name="ListView"
SelectionMode="Single"
SelectionChanged="ListView_OnSelectionChanged"
Grid.Row="1"
Margin="8,16"
>
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding DisplayName}"
FontSize="{Binding Path=FontSizeListViewTitle}" Margin="6,0,0,0" TextWrapping="NoWrap" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
的問題是,字號=「{綁定路徑= FontSizeListViewTitle}」似乎並沒有正常工作。它顯示的字體大小接近6(或某些東西),儘管變量FontSizeListViewTitle只取值在16和24之間。
有趣的是,如果我將TextBlock放在ListView之外作品完美。只有當我嘗試在ListView中使用綁定時纔會出現此問題。 此外,文本=「{結合顯示名稱}完美的作品與文本塊表明,它具有顯示文本
從一些的.cs代碼文件現在。
private int _fontSizeListViewTitle;
public int FontSizeListViewTitle
{
get { return _fontSizeListViewTitle; }
set
{
_fontSizeListViewTitle = value;
OnPropertyChanged("FontSizeListViewTitle");
}
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
internal void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
public MainPage()
{
InitializeComponent();
this.DataContext = this;
ListView.ItemsSource = MyList; // MyList is an Observable Collection
}
它不會返回任何錯誤,但是當我運行程序並嘗試將元素添加到ListView時,應用程序崩潰。 – TheQuestioner
如果我嘗試做一些像並從代碼更改FontSize的東西會怎麼樣?問題是我不知道如何訪問TitleTextBlock。 ListView.TitleTextBlock不起作用。 –
TheQuestioner