C#WPF,旨在执行某项操作但不执行任何操作的代码. [英] C# WPF, A code that is meant to do something but doesn't.............

查看:117
本文介绍了C#WPF,旨在执行某项操作但不执行任何操作的代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我的全部代码

XML

this is all my code

XML

<Window x:Class="AttoSurf.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="AttoSurf" Height="300" Width="400" WindowStyle="None" MinWidth="400" MinHeight="300" >
    <Grid>
        <StackPanel Height="33" HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Top" Margin="0,17,0,0"></StackPanel>
        <TabControl Height="161" HorizontalAlignment="Left" Margin="24,67,0,0" Name="tabControl1" VerticalAlignment="Top" Width="282" TabStripPlacement="Top">
            <TabItem Header="O" Name="tabItem1" IsEnabled="False" BorderBrush="Black" Background="Black" Foreground="#FF1C1C1C" OpacityMask="Black" BorderThickness="2">
                <Grid />
            </TabItem>
        </TabControl>
    </Grid>
</Window>



C#代码



the C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AttoSurf
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.AddHandler(CloseableTabItem.CloseTabEvent, new RoutedEventHandler(this.CloseTab));
        }






public class CloseableTabItem : TabItem

{

    static CloseableTabItem()

    {

        //This style is defined in themes\generic.xaml

        DefaultStyleKeyProperty.OverrideMetadata(typeof(CloseableTabItem),

            new FrameworkPropertyMetadata(typeof(CloseableTabItem)));

    }



    public static readonly RoutedEvent CloseTabEvent =

        EventManager.RegisterRoutedEvent("CloseTab", RoutingStrategy.Bubble,

            typeof(RoutedEventHandler), typeof(CloseableTabItem));



    public event RoutedEventHandler CloseTab

    {

        add { AddHandler(CloseTabEvent, value); }

      remove { RemoveHandler(CloseTabEvent, value); }

    }



    public override void OnApplyTemplate()

    {

        base.OnApplyTemplate();



        Button closeButton = base.GetTemplateChild("PART_Close") as Button;

        if (closeButton != null)

            closeButton.Click += new System.Windows.RoutedEventHandler(closeButton_Click);

    }



    void closeButton_Click(object sender, System.Windows.RoutedEventArgs e)

    {

        this.RaiseEvent(new RoutedEventArgs(CloseTabEvent, this));

    }

}



现在由于某种原因,当我调试程序时,关闭按钮没有出现在选项卡上,有人可以告诉我出了什么问题并告诉我如何修复吗?



now for some reason the close button doesn''t appear on the tabs when i debug the program, can some one please tell me what is wrong and tell me how i can be fixed?

推荐答案

您是否要在窗口中使用CloseableTabItem 而不是TabItem ?

如果是这种情况,请首先添加一个新的名称空间:
Are you trying to use the CloseableTabItem instead of the TabItem in your window?

If that''s the case, first add a new namespace:
...
xmlns:myclasses="clr-namespace:AttoSurf"
...


并在XAML中使用正确的类:


And use the correct class in XAML:

...
<myclasses:CloseableTabItem Header="O" x:Name="tabItem1" IsEnabled="False" BorderBrush="Black" Background="Black" Foreground="#FF1C1C1C" OpacityMask="Black" BorderThickness="2">
    <Grid />
</myclasses:CloseableTabItem>
...


这篇关于C#WPF,旨在执行某项操作但不执行任何操作的代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆