0

我有一个图像编辑器,它在画布上有许多图像元素和文本元素。我有两个单独的选项卡,允许用户重新调整文本或图像的大小。我想在选择文本元素时切换到文本选项卡,并在选择图像时切换到图像选项卡。我很难弄清楚该怎么做。

MainPage.xaml -

<!-- Control Panel -->
<sdk:TabControl x:Name="elementEditor" Margin="10,0,10,19" Width="215" Background="#FFD6D6D6"
       Grid.RowSpan="2">//removed selectedIndex binding from here
<sdk:TabItem x:Name="tabCanvasSettings" DataContext="{Binding Project}">
    <sdk:TabItem.Header x:Name="tabCanvas">
        <TextBlock Text="Canvas" />
    </sdk:TabItem.Header>
    <sdk:TabItem.Content>
        <!-- Content -->
    </sdk:TabItem.Content>
</sdk:TabItem>

<!-- Text tab -->
<sdk:TabItem x:Name="tabText" IsSelected="{Binding Path=TabTextSel}">
    <sdk:TabItem.Header>
        <TextBlock Text="Text" />
    </sdk:TabItem.Header>
    <sdk:TabItem.Content>
        <!-- Content -->
    </sdk:TabItem.Content>
</sdk:TabItem>

<!-- Image tab -->
<sdk:TabItem x:Name="tabImage" IsSelected="{Binding Path=TabImgSel}">
    <sdk:TabItem.Header>
        <TextBlock Text="Image" />
    </sdk:TabItem.Header>
    <sdk:TabItem.Content>
        <!-- Content -->
    </sdk:TabItem.Content>
</sdk:TabItem>
</sdk:TabControl>

Project.cs(不是我的 MainPage 代码隐藏)-

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using ImageEditor.Client.Behaviors;
using ImageEditor.Client.Views;
using System.Linq;
using ImageEditor.Client.ImageDesignerService;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace ImageEditor.Client.BLL
{
  public class Project : INotifyPropertyChanged
  {
    private bool tabTextSel;
    public bool TabTextSel
    {
        get { return tabTextSel; }
        set
        {
            tabTextSel = value;
            NotifyPropertyChanged("TabTextSel");
        }
    }

    private bool tabImgSel;
    public bool TabImgSel
    {
        get { return tabImgSel; }
        set
        {
            tabImgSel = value;
            NotifyPropertyChanged("TabImgSel");
        }
    }
    //Other properties and methods

    public void element_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
        this.SelectedElement = sender as FrameworkElement;
        if (sender is TextBlock)
        {
            this.SelectedTextElement = sender as TextBlock;

            //Change tab to text tab
            tabImgSel = false;
            tabTextSel = true;
        }
        else if (sender is Image)
        {
            this.SelectedImageElement = sender as Image;

            //Change tab to image tab
            tabTextSel = false;
            tabImgSel = true;
        }

    }

  }
}

我如何让它在这里切换标签?我敢肯定,这可能很简单,我只是无法解决。当我调试时,这些值似乎很好地传递给了绑定,但它们仍然没有正确切换

4

2 回答 2

1

您的属性(TabTextSel 和 TabImgSel)应该是 bool 类型,而不是字符串。您应该将它们设置为 true 或 false (bool)。

于 2012-08-07T10:41:08.323 回答
0

您必须分配给属性而不是变量,以便数据绑定可以通过调用您的 NotifyPropertyChanged 方法来工作......

于 2012-12-20T14:23:05.360 回答