问题
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>
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>
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);
}
Here Is Image Measurement
public void Img_Measurement()
{
IsEnableZoom = false;
IsEnableCanvas = true;
MessageBox.Show("Image Measurement Starts", "Alert", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
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
}
}
And Here is Property For Enabling
public bool IsEnableZoom
{
get
{
return _isEnableZoom;
}
set
{
_isEnableZoom = value;
NotifyOfPropertyChange(() => IsEnableZoom);
}
}
public bool IsEnableCanvas
{
get
{
return _isEnableCanvas;
}
set
{
_isEnableCanvas = value;
NotifyOfPropertyChange(() => IsEnableCanvas);
}
}
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
回答1:
Disabled elements don't raise mouse events. This is by design.
From the docs:
Elements that are not enabled do not participate in hit testing or focus and therefore will not be sources of input events.
The obvious solution is not to disable the Canvas
. You may still make it look and/or behave like it was disabled.
来源:https://stackoverflow.com/questions/64029418/enable-child-control-while-custom-parent-is-disabled-in-wpf-c-sharp