【发布时间】:2018-11-24 16:00:03
【问题描述】:
我正在制作一个自定义图表控件。所以我想要的是当用户将鼠标悬停在椭圆上时,显示有关椭圆的信息。所以椭圆是带有频率和八进制的注释,我想显示该信息。但我不想使用消息框,我只想像一个会弹出信息的绿色气泡一样。
我遇到的问题是我什至没有看到我的控件的悬停事件。 这是我的代码:
<UserControl x:Class="Baileys.CustomChartControl"
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:local="clr-namespace:Baileys"
mc:Ignorable="d"
d:DesignHeight="81.855" Loaded ="UserControl_Loaded" MouseDoubleClick="UserControl_DoubleClick" MouseDown="UserControl_MouseDown" Width="759.405" >
<Grid x:Name="grid" Background="Transparent" Margin="0,0,-368,-23">
<Canvas x:Name="canvas">
<Image Source ="C:\Users\bboone\Pictures\note1.jpg" HorizontalAlignment="Left" Height="80" Margin="10,0,0,0" VerticalAlignment="Top" Width="67"/>
<Line x:Name="xAxis" X1="0" Y1="80" X2="754" Y2="80" Margin="5,0,210,-5"
Stroke="Black" StrokeThickness="2"/>
<Line x:Name="YAxis" X1="0" Y1="0" X2="0" Y2="80" Margin="5,0,0,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
<Line x:Name="xAxis1" X1="0" Y1="0" X2="754" Y2="0" Margin="5,0,71,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
<Line x:Name="xAxis2" X1="0" Y1="20" X2="754" Y2="20" Margin="5,0,71,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
<Line x:Name="xAxis3" X1="0" Y1="40" X2="754" Y2="40" Margin="5,0,71,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
<Line x:Name="xAxis4" X1="0" Y1="60" X2="754" Y2="60" Margin="5,0,71,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
<Line x:Name="xAxis5" X1="0" Y1="20" X2="754" Y2="20" Margin="5,0,71,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
<Line x:Name="YAxis2" X1="754" Y1="0" X2="754" Y2="80" Margin="-5,0,10,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
<Line x:Name="YAxis3" X1="748" Y1="0" X2="748" Y2="80" Margin="10,0,-6,-4.8"
Stroke="Black" StrokeThickness="2" Grid.RowSpan="3"/>
</Canvas>
</Grid>
知道为什么,但没有鼠标悬停。 这是我制作椭圆的代码:
private void WholeNote(Point circlePoints)
{
int x = (int)(circlePoints.X + circlePoints.Y);
double cubePanelSize = Math.Min(this.Width, this.Height);
double innerSize = cubePanelSize / 3;
double outerSize = cubePanelSize / 3;
Ellipse ellipse = new Ellipse();
ellipse.Height = outerSize / 2;
ellipse.Width = outerSize / 2;
ellipse.Fill = Brushes.Gray;
ellipse.StrokeThickness = 3;
Canvas.SetTop(ellipse, circlePoints.Y);
Canvas.SetLeft(ellipse, circlePoints.X);
locations.Add(canvas.Children.Add(ellipse));
DoubleAnimation ani = new DoubleAnimation
{
From = 0,
To = ellipse.Width,// Convert.ToDouble(i),
Duration = new TimeSpan(0, 0, 2)
};
//Add animation
ani.FillBehavior = FillBehavior.HoldEnd;
ellipse.BeginAnimation(HeightProperty, ani);
ellipse.Effect = new DropShadowEffect
{
Color = new Color { A = 1, R = 0, G = 139, B = 139 },
Direction = 45,
ShadowDepth = 10,
Opacity = 0.8,
BlurRadius = 10
};
}
所以当用户点击图表时,它会变成一个椭圆
那么谁能帮帮我?
【问题讨论】:
-
如果您在用户控件中使用画布作为主机,则控件将不会剪辑。这意味着你可以在它“外面”展示一些东西。像一个绿色的泡泡。 EG使用负canvas.top,它会在上面。您可以使用触发器来启动情节提要,并在您的用户控件上比较 ismouseover。把那一点放在这样的风格stackoverflow.com/questions/2388429/…。
-
我会做大部分你在 xaml 中得到的东西,而不是代码。
-
安迪,所以我对 WPF 非常陌生,每个人都说在 xaml 中做更多的事情,但你会如何在 xaml 中做呢?用户需要能够单击图表并在用户单击的位置放置一个椭圆,您不能在 xaml 中这样做吗?我有那部分在 C# 代码中工作。