2015-06-13 132 views
2

我有一个使用AvalonDock的窗口管理器项目。数据绑定不能在Avalondock窗口上工作

基本上在两个元素:一个LayoutAnchorableItem展示我不同的工具盒(目前之一,由树视图)和一个LayoutItem以示与树视图打开的文档(自定义控制,具有可绑定的参数 - 在理论上)

DockingManager的ViewModel托管名为PanesObservableCollection,它将是LayoutItems。如果我不尝试绑定在XAML中的参数,并迫使这样

<avalonDock:DockingManager.LayoutItemTemplateSelector> 
    <panes:PanesTemplateSelector> 
     <panes:PanesTemplateSelector.ExchangeViewTemplate> 
      <DataTemplate> 
       <xchng:Exchange/> 
      </DataTemplate> 
     </panes:PanesTemplateSelector.ExchangeViewTemplate> 
     <panes:PanesTemplateSelector.GraphViewTemplate> 
      <DataTemplate> 
       <grph:Graph TickerCode="ILD" ExchangeCode="EPA"/> 
      </DataTemplate> 
     </panes:PanesTemplateSelector.GraphViewTemplate> 
    </panes:PanesTemplateSelector> 
</avalonDock:DockingManager.LayoutItemTemplateSelector> 

Exchange

事作品“精”是工具箱和Graph是LayoutItems。

为对接经理的初始数据绑定就像下面这样:

<avalonDock:DockingManager Margin="0,0,0,0" 
         Grid.Row="1" 
         AnchorablesSource="{Binding Tools}" 
         DocumentsSource="{Binding Panes}" 
         ActiveContent="{Binding ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}" 
         x:Name="dockManager"> 

注意,面板是有两个公共参数GraphViewModel类型:ExchangeCodeTickerCode

事情是我想要将TickerCodeExchangeCode绑定到Panes.TickerCode和Panes.ExchangeCode值。

所以,我想这一点:

<grph:Graph TickerCode="{Binding TickerCode, UpdateSourceTrigger=PropertyChanged}" ExchangeCode="{Binding ExchangeCode, UpdateSourceTrigger=PropertyChanged}"/> 

但不起任何作用:TickerCode和ExchangeCode在自定义控件等于""相反,当我强迫在XAML的值。

此外有点奇怪的是,如果我在代码执行中,Panes实际上具有TickerCode和ExchangeCode的值,它们只是不绑定。例如,实际创建窗格的代码是

public void AddGraph(string FullName, string ExchangeCode, string TickerCode) 
    { 
     var graphViewModel = new GraphViewModel(FullName, ExchangeCode, TickerCode); 
     _panes.Add(graphViewModel); 
     ActiveDocument = graphViewModel; 

    } 

这里,每一步都有两个值。让我们想象一下,我添加了5个不同的窗格,它们都具有正确的ExchangeCode和TickerCode,但没有任何内容被传递给自定义控件。

如果您需要更多关于我的自定义控件的值,请将值绑定到以下代码:Passing parameters to custom control (databinding)

备注:正如您所看到的,我并未放置大部分代码,如果您认为它可能有所帮助,请提出要求,我将添加所需内容。请注意,整个窗口管理器的全局逻辑与AvalonDock测试应用程序(AvalonDock.MVVMTestApp)中提供的相同。

+0

我想我正在使用的数据绑定方法存在问题。如果拿出与我目前的问题无关的所有东西,并创建一个空白项目,只用一个带有datacontext的自定义控件Graph来创建一个只有两个参数的空白项目,并将它们绑定到自定义控件:同样的问题,尽管参数实际上存在于datacontext,但不传递给自定义控件。我会看看那里... –

回答

0

例如,如果我有ChartView和ChartViewModel: 在MainWindow中。XAML:

<xcad:DockingManager x:Name="dockingManager" 
         AnchorablesSource="{Binding Path=Anchorables}" 
         DocumentsSource="{Binding Path=Documents}" 
         ActiveContent="{Binding Path=ActiveDocument, Mode=TwoWay, Converter={StaticResource ActiveDocumentConverter}}"> 

     <xcad:DockingManager.LayoutItemTemplateSelector> 
      <selfViewPane:PaneTemplateSelector> 
       <selfViewPane:PaneTemplateSelector.ChartViewTemplate> 
        <DataTemplate> 
         <selfViewDocument:ChartView /> 
        </DataTemplate> 
       </selfViewPane:PaneTemplateSelector.ChartViewTemplate> 
      </selfViewPane:PaneTemplateSelector> 
     </xcad:DockingManager.LayoutItemTemplateSelector> 

     <xcad:DockingManager.LayoutItemContainerStyleSelector> 
      <selfViewPane:PaneStyleSelector> 
       <selfViewPane:PaneStyleSelector.ChartViewStyle> 
        <Style TargetType="{x:Type xcad:LayoutItem}"> 
         <Setter Property="Title" Value="{Binding Model.Title}"/>         
         <Setter Property="CloseCommand" Value="{Binding Model.CloseCommand}"/> 
         <Setter Property="IconSource" Value="{Binding Model.IconSource}"/> 
         <Setter Property="ContentId" Value="{Binding Model.ContentId}"/> 
        </Style> 
       </selfViewPane:PaneStyleSelector.ChartViewStyle> 
      </selfViewPane:PaneStyleSelector> 
     </xcad:DockingManager.LayoutItemContainerStyleSelector> 

     <xcad:DockingManager.LayoutUpdateStrategy> 
      <selfViewPane:LayoutInitializer /> 
     </xcad:DockingManager.LayoutUpdateStrategy> 

     <xcad:LayoutRoot> 
      <xcad:LayoutPanel Orientation="Horizontal"> 
       <xcad:LayoutAnchorablePane Name="ToolsPane" DockWidth="200"> 
       </xcad:LayoutAnchorablePane> 
       <xcad:LayoutDocumentPane /> 
      </xcad:LayoutPanel> 
     </xcad:LayoutRoot>     
    </xcad:DockingManager> 

和: 在ChartViewModel我有物业ChartPlotModel:

/// <summary> 
/// Gets or sets the ChartPlotModel. 
/// </summary> 
public PlotModel ChartPlotModel 
{ 
    get 
    { 
     return this.chartPlotModel; 
    } 

    set 
    { 
     if (this.chartPlotModel != value) 
     { 
      this.chartPlotModel = value; 
      this.RaisePropertyChanged("ChartPlotModel"); 
     } 
    } 
} 

在ChartView我可以绑定:

<UserControl x:Class="Jofta.Analyzer.UI.Classes.View.Document.ChartView" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" 
      xmlns:oxy="http://oxyplot.org/wpf" 
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"> 

    <xctk:BusyIndicator IsBusy="{Binding Path=IsBusy}"> 
     <Grid> 
      <oxy:PlotView Model="{Binding ChartPlotModel}" /> 
     </Grid> 
    </xctk:BusyIndicator> 

</UserControl> 

在这个例子中,我结合PlotView从oxyplot,但我认为,你可以使用这种模式。你有GraphViewModel,GraphView和TickerCode和ExchangeCode。

+0

除非我错过了一些东西,这并不能回答我的问题。我想我没有足够清楚地解释它。我所知道的是,在主窗口中有一个自定义控件,然后在这个自定义控件中绑定数据。我的目标是将数据从MainWindow xaml绑定到自定义控件,以便将一些参数传递给控件,​​这些参数将根据这些参数将数据绑定到控件的xaml(事实上,一个oxyplot图:)) –

+0

对不起,我没有回答你的问题。我不确定我能理解你到底需要什么。在我的例子中,我有MVVM模式。从对象资源管理器树视图(LayoutAnchorableItem)我打开图表(LayoutItem)。 – Jofta

+0

不要对不起Jofta,这是非常好的,很好,试图帮助:)我想尽快找到一些关于数据绑定的教程,我想我可以在改进后适应它它。 –