10

リボン タブがクリックされたときに、WPF アプリケーションでメイン サーフェス (リボン自体の下のもの) のコンテンツを変更したいと考えています。私はオフィスのリボンを使用していますが、それは大した問題ではありません。では、どの WPF コンテナー コントロールを使用する必要があり、どのように使用すればよいでしょうか? 可視性を非表示にしたさまざまなコントロールを用意する必要がありますか、それとも何ですか。私は WPF の専門家ではないので、少しインスピレーションが必要です。

4

4 に答える 4

11

これがこれを行うための最良の方法であるとは思えないと言って、序文を書きます。

これは、RibbonTab 通知の私のスタイルです IsSelected は、ビュー モデルで IsSelected にバインドされます

  <!-- RibbonTab -->
        <Style TargetType="{x:Type ribbon:RibbonTab}">
            <Setter Property="ContextualTabGroupHeader" Value="{Binding ContextualTabGroupHeader}" />
            <Setter Property="Header" Value="{Binding Header}" />
            <Setter Property="ItemsSource" Value="{Binding GroupDataCollection}" />
            <Setter Property="IsSelected" Value="{Binding IsSelected}" />
        </Style>

これはビューモデルのコードです

    public bool IsSelected
    {
        get
        {
            return _isSelected;
        }

        set
        {
            if (_isSelected != value)
            {
                _isSelected = value;
                OnPropertyChanged(new PropertyChangedEventArgs("IsSelected"));
            }
        }
    }
    private bool _isSelected;

TabViewModel のコンストラクターで、コンテンツの ViewModel のパラメーターを取得します

    public TabData(ISelectedContentTab content)
        : this(content.DisplayName)
    {
        _selectedContent = content;
    }

    private ISelectedContentTab _selectedContent;

次に、ItemsControl を使用して、選択したコンテンツを xaml に表示しました

  <ItemsControl Grid.Row="1" VerticalContentAlignment="Stretch" VerticalAlignment="Stretch" 
                  ItemsSource="{Binding ElementName=ribbon,Path=SelectedItems}" 
                  ItemTemplate="{StaticResource ContentControlTemplate}" />

そして、私が持っている ContentControlTemplate は

 <DataTemplate x:Key="ContentControlTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <ContentControl Grid.Row="0" VerticalAlignment="Stretch" Height="Auto" VerticalContentAlignment="Stretch" Content="{Binding SelectedContent}" />
            </Grid>
        </DataTemplate>

また、コンテンツがビューを指すデータテンプレートがあることを確認してください

お役に立てれば。

于 2010-08-23T18:34:22.237 に答える
2

もっと簡単な方法があると思います。私はこのようにしました:

<Frame NavigationUIVisibility="Hidden" x:Name="FrmMainFrame" DockPanel.Dock="Bottom"/>

そしてあなたのコードビハインドで:

mainWindowView.RibMain.SelectionChanged += RibMain_SelectionChanged;

void RibMain_SelectionChanged(object sender,  System.Windows.Controls.SelectionChangedEventArgs e)
    {
        var tab = this.mainWindowView.RibMain.SelectedItem as RibbonTab;
        if (tab.Header.Equals("Explorer"))
        {
            mainWindowView.FrmMainFrame.Navigate(explorerController.View());
        }
        else
            mainWindowView.FrmMainFrame.NavigationService.Navigate(new Uri("http://www.google.com/"));
    }
于 2013-06-13T08:07:29.013 に答える
1

私は解決策を発見しました:

後ろのコードで処理できるように、RibbonTabに名前を付けます。ビューとコントロールを追加する方法は複数あることは知っていますが、これが私が行ったことです...リボンの後にメイングリッド内のビューに新しいグリッドを追加しただけです。すなわち:

<r:RibbonWindow>
  <Grid>
    <r:Ribbon>
      <r:RibbonTab Name="Tab1" Header="Home">
        <r:RibbonGroup Name="Group1">
          <r:RibbonButton LargeImageSource="images\icon.png" Label="Click Me"/>
        </r:RibbonGroup>
      </r:RibbonTab>
      <r:RibbonTab Name="Tab2" Header="Other Tab">
        <r:RibbonGroup Name="Group2">
          <r:RibbonButton LargeImageSource="images\icon.png" Label="Click Me"/>
        </r:RibbonGroup>
      </r:RibbonTab>
    </r:Ribbon>
    <Grid Name="Tab1RTB" Grid.Row="1" Visibility="Hidden">
      <RichTextBox Margin="5" BorderBrush="LightGray" BorderThickness="1"/>
    </Grid>
    <Grid Name="Tab2RTB" Grid.Row="1" Visibility="Hidden">
      <RichTextBox Margin="5" BorderBrush="LightGray" BorderThickness="1"/>
    </Grid>
  </Grid>
</r:RibbonWindow>

次に、コードビハインド(VB.NET)

Private Sub TabChanged(sender As System.Object, e As SelectionChangedEventArgs) Handles ribbonHome.SelectionChanged
  If Tab1.IsSelected = True Then
    Tab1RTB.Visibility = Windows.Visibility.Visible
    Tab2RTB.Visibility = Windows.Visibility.Collapsed
  ElseIf Tab2.IsSelected = True
    Tab1RTB.Visibility = Windows.Visibility.Collapsed
    Tab2RTB.Visibility = Windows.Visibility.Visible
  Else
    Tab1RTB.Visibility = Windows.Visibility.Collapsed
    Tab2RTB.Visibility = Windows.Visibility.Collapsed
  End If
End Sub
于 2012-12-28T18:07:20.180 に答える