2011-07-25 29 views
1
App.xaml 
<Application.Resources> 
. . . . 
<StackPanel> 
<ItemsPresenter/> 
<ListBox x:Name="comm_box" ItemsSource="{Binding}"> 
. .. . 
</Application.Resources> 

錯誤:comm_box不會在目前情況下通過名字來訪問靜態資源列表框

存在如何解決這個問題呢? 我有listbox-news和listbox-comments在listbox-news 之後顯示但是我不能設置comm_box.Itemssource,因爲comm_box是不可見的。 請幫幫我。 http://pastebin.com/DERdgHJ9

回答

1

嘗試Application.Current.Resource [ 「comm_box」]

+0

沒有更迭...此外我嘗試:'VAR comm_x =從i在this.Resources 其中i.Key.ToString() ==「comm_box」 select i; ListBox comm_box = comm_x as ListBox; comm_box.ItemsSource = comm_c;' – SevenDays

+0

你有同樣的錯誤嗎?你應該可以做ListBox; = ListBox box = Application.Current.Resources [「comm_box」]; box.ItemsSource = somethingsomething; ' 這對我來說工作得很好。 – Egor

+0

是的。我遇到了同樣的錯誤:NullReferenceException – SevenDays