【问题标题】:wpf ellipse remove blue border on clickwpf椭圆在单击时删除蓝色边框
【发布时间】:2016-04-18 22:34:38
【问题描述】:

单击按钮时,我在cs文件中动态生成了一些椭圆。问题是当我单击任何椭圆时,边框颜色变为蓝色,如图所示。请问如何去除蓝色背景。

private void btn1_Click(object sender, RoutedEventArgs e)
        {
            imgBrush.ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/AthenaIsolatedFeatures;component/Widget/Pointers/top.png", UriKind.RelativeOrAbsolute));
            imgBrush.Stretch = Stretch.Fill;
            ele.Fill = imgBrush;
            lstBox.Items.Clear();
            CircularPanel.AngleRadians((sender as Button).Name);
            for (int i = 0; i < 4; i++) //Assuming 3 images to be created
            {
                ImageBrush brush = new ImageBrush();
                brush.ImageSource = new BitmapImage(new Uri(@"pack://application:,,,/AthenaIsolatedFeatures;component/Widget/SubImages/Target" + (i + 1) + ".png", UriKind.RelativeOrAbsolute));
                Ellipse ellipse = new Ellipse()
                {
                    Name = "Target" + i.ToString(),
                    Height = 70,
                    Width = 70,
                    Stroke = new SolidColorBrush(Colors.Black),
                    StrokeThickness = 1,

                };

                ellipse.Fill = brush;
                ellipse.MouseLeftButtonDown += Ellipse_MouseLeftButtonDown1;
                lstBox.Items.Add(ellipse);
            }
        }

现在,当点击每个动态生成的椭圆时,我想做点什么

 private void Ellipse_MouseLeftButtonDown1(object sender, MouseButtonEventArgs e)
        {

          //Do something
        }

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    对于点击,而不是

    ellipse.MouseLeftButtonDown += Ellipse_MouseLeftButtonDown1;
    

    你可以试试

    e.MouseLeftButtonDown += Ellipse_MouseLeftButtonDown1;
    

    而对于后台,你可以在 XAML 代码中尝试

    <Ellipse Width="50" Height="50" Stroke="Blue" StrokeThickness="10" Fill="Transparent"></Ellipse>
    

    希望这会有所帮助。

    【讨论】:

    • 问题是,如果您看到我的代码,我在后面的代码中正在执行类似 Ellipse e=new Ellipse() 的操作。要删除那个蓝色背景,我需要为椭圆应用并调用一些样式。如果我说 e.Fill=Brushes.Transparent 则椭圆的内容将被删除。我仍然不确定您的 xaml 将如何提供帮助。
    • 我没有椭圆的任何 xaml。我正在动态生成它。
    • 但是看我的 for 循环。我想同时生成 4 个椭圆,每个椭圆的内容都需要改变。如果我在 xaml 中执行此操作,我将只能创建 1 个。
    • 您可以创建一个独特的 eclipse.xaml,它只包含您需要的图形,然后在您的循环中只调用它就完成了。我在最近的一个项目中做过类似的事情,我自己找找,给你举个例子。
    猜你喜欢
    • 2021-06-04
    • 1970-01-01
    • 2017-07-02
    • 2018-04-03
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 2014-07-02
    相关资源
    最近更新 更多