Проблема в том, что когда мышь перемещается через ListBox
, она должна следовать перекрестию двух пересекающихся линий. Код Xaml:
<TabControl x:Name="Drawing_TabControl"
Grid.Row="0"
Background="WhiteSmoke"
SelectionChanged="Drawing_TabControl_SelectionChanged"
ItemsSource="{Binding Files}"
SelectedItem="{Binding SelectedFile_M}"
MouseLeftButtonDown="Drawing_TabControl_MouseLeftButtonDown"
MouseMove="Drawing_TabControl_MouseMove"
MouseLeftButtonUp="Drawing_TabControl_MouseLeftButtonUp">
<TabControl.ItemTemplate>
<DataTemplate DataType="{x:Type local1:File_M}">
<StackPanel Orientation="Horizontal"
Background="Transparent">
<TextBlock Text="{Binding Path=Name_File}" Background="Transparent" />
<Button Height="18"
Width="18"
Background="Transparent"
BorderBrush="Transparent"
Click="Close_TabItem"
Visibility="{Binding IsSelected, RelativeSource={RelativeSource FindAncestor, AncestorType=TabItem},
Converter={StaticResource B2V}}">
<Image Source="icons\close_x.png"/>
</Button>
</StackPanel>
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate DataType="{x:Type local1:File_M}">
<Grid Background="WhiteSmoke">
<ListBox x:Name="a"
Background="GhostWhite"
Height="6cm"
Width="16cm"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ItemsSource="{Binding Path=Figures}"
SelectedItem="{Binding Path=SelectedFigure_M}"
Tag="listbox">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type local2:Figure_M}">
<Grid>
<Line x:Name="hor"
X1="0"
Y1="{Binding Path=YMove}"
X2="500"
Y2="{Binding Path=YMove}"
Stroke="DarkRed"
StrokeThickness="0.5" />
<Line x:Name="ver"
X1="{Binding Path=XMove}"
Y1="0"
X2="{Binding Path=XMove}"
Y2="100"
Stroke="DarkRed"
StrokeThickness="0.5" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
Код C#:
private void Drawing_TabControl_MouseMove(object sender, MouseEventArgs e)
{
tag = "listbox";
var figure_M = sender as Figure_M;
figure_M.XMove = e.GetPosition(Drawing_TabControl).X;
figure_M.YMove = e.GetPosition(Drawing_TabControl).Y;
}
В настоящее время возникает исключение, когда мышь находится над TabItem
: System.NullReferenceException: "The object reference does not point to an instance of the object."