在WPF C#中禁用自定义父级时启用子控件
您好,我为缩放Picture定制了父控件.在该控件内有子画布,在画布内有子图像控件.我创建了一个用于缩放和图像测量的菜单.我还可以测量图像的坐标.我禁用父级ZoomBorder控件时遇到的问题是我无法触发Child Image事件.我可以禁用名为ZoomBorder的ZoomControl,但是我想要MouseDown的图像事件.当启用Zoomcontrol并可以正常工作时,我可以禁用子图像事件.这是我的代码.
Hello I made custom made parent control for zooming Picture . Inside That Control there is child canvas and inside Canvas There is child image Control . And I created A menu for Zoom and Image measuring . I also can able to measure co Ordinates the image . My problem when I disabled Parent ZoomBorder control I cannot triggering event of Child Image . I can disable ZoomControl named ZoomBorder but I want image event of MouseDown . I can Disable child Image event when Zoomcontrol enabled and It works. Here is my code .
<utils:ZoomBorder x:Name="ZoomBorder" IsEnabled="{Binding IsEnableZoom}" ClipToBounds="True" Background="Gray" Grid.Row="3" Grid.Column="2" Grid.ColumnSpan="4">
<Canvas IsEnabled="{Binding IsEnableCanvas}">
<Image x:Name="DIIMGFINAL" cal:Message.Attach="[Event MouseDown] = [Action MDownCalCulateDistance($source, $eventArgs)];
[Event MouseUp] = [Action MUpCalCulateDistance($source, $eventArgs)];
[Event MouseMove] = [Action MMoveCalCulateDistance($source, $eventArgs)]"/>
<Line IsHitTestVisible="False" X1="{Binding FirstPoint.X}" Y1="{Binding FirstPoint.Y}"
X2="{Binding SecondPoint.X}" Y2="{Binding SecondPoint.Y}"
Stroke="Red" StrokeThickness="3"/>
</Canvas>
</utils:ZoomBorder>
这是菜单项ImageMeasuring和Zoom
And Here is The Menu Item ImageMeasuring and Zoom
<Menu Grid.ColumnSpan="3" Grid.Column="1" Grid.Row="0" Background="Transparent" >
<MenuItem x:Name="ズームControl" Header="ズーム">
<!--Item For Zoom-->
</MenuItem>
<MenuItem x:Name="Img_Measurement" Header="Image Measurement">
<!--Item For Measure-->
</MenuItem>
</Menu>
这是我的C#代码以进行缩放激活
Here is My C# code For Zoom Activation
public void ズームControl()
{
//For Only Zoom
IsEnableZoom = true;
IsEnableCanvas = false;
MessageBox.Show("Zoom Control Starts", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
这里是图像测量
public void Img_Measurement()
{
IsEnableZoom = false;
IsEnableCanvas = true;
MessageBox.Show("Image Measurement Starts", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
这是我的图像MouseDown事件
Here Is My Image MouseDown Event
public void MDownCalCulateDistance(object sender, System.Windows.Input.MouseEventArgs e)
{
f (IsEnableCanvas == false) return;
if (!(sender is System.Windows.Controls.Image)) return;
try{
//Code Here
}
Catch(Exception ex){
//code here
}
}
这是要启用的属性
public bool IsEnableZoom
{
get
{
return _isEnableZoom;
}
set
{
_isEnableZoom = value;
NotifyOfPropertyChange(() => IsEnableZoom);
}
}
public bool IsEnableCanvas
{
get
{
return _isEnableCanvas;
}
set
{
_isEnableCanvas = value;
NotifyOfPropertyChange(() => IsEnableCanvas);
}
}
如您所见,当我关闭ZoomControl的ZoomBorder时,我无法进行MouseDown事件.当启用Parent事件的ZoomBorder时,我可以使Mousedown消失.请帮我 .预先感谢
As You can See When I disbled the ZoomBorder of ZoomControl I cannot go The MouseDown Event . I can Mousedown disbled when ZoomBorder of Parent event enabled . Please Help me . Thanks in advance
禁用的元素不会引发鼠标事件.这是设计使然.
Disabled elements don't raise mouse events. This is by design.