簡體   English   中英

綁定到ItemsSource屬性上ItemsControl中的動態資源

[英]binding to dynamic resource in ItemsControl on the ItemsSource Property

嘿,我希望有人能為我回答幾個問題。 我應該如何確保綁定到itemsource的數據動態更新? 我無法將綁定源從staticresource更改為動態資源,因為Object Binding的Source屬性不是依賴項對象的依賴項屬性。

綁定到靜態資源到底意味着什么? 我認為綁定到動態資源將意味着當資源更改時依賴項屬性也會更新。

綁定到靜態資源是否僅附加資源的初始值?

我的目標只是基於signal_data更新signal_viewer。

<UserControl.Resources>
    <wpfExp:SignalData x:Key="signal_data" />
</UserControl.Resources>

<DockPanel x:Name ="maindockpanel"  Height ="Auto" Width ="Auto" LastChildFill="True">
  <ToolBarTray DockPanel.Dock="Top">
    <ToolBar HorizontalAlignment="Stretch" VerticalAlignment="Top">
      <Button Name="load_button" Height="20" Width="Auto" Click="Load_Button_Click">Load</Button>
      <Button Name="zoom_in_button" Click="zoom_in_button_Click">Zoom In</Button>
      <Button Name="zoom_out_button" Click="zoom_out_button_Click">Zoom Out</Button>
    </ToolBar>
  </ToolBarTray>

  <ItemsControl x:Name ="Signalviewer_Control" ItemsSource="{Binding Source = {StaticResource signal_data}, Path = list_of_signals}">
    <ItemsControl.ItemTemplate>
      <DataTemplate>
        <wpfExp:SignalViewer Signal="{Binding}" MainText="{Binding Path = SignalName}"/>
      </DataTemplate>
    </ItemsControl.ItemTemplate>
  </ItemsControl>

由於您提到的所有這些問題,我都反對將ViewModel或數據作為Resource放入XAML中。

相反,可以在后面的代碼中分配DataContext

public SomeWindow() //Window Constructor
{
    DataContext = new SomeViewModel();
}

或使用ViewModelLocator

或使用此處概述的RegisterDataTemplate方法。


無論如何,如果要快速解決此問題,請將list_of_signalsList<T>更改為ObservableCollection<T>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM