У меня есть (надеюсь) интересный вопрос.
Прежде всего, что я пытаюсь сделать здесь:
Я пытаюсь создать набор в виде круговой диаграммыкнопки, позже этот элемент управления будет использоваться в приложении с сенсорным экраном.Элемент управления рисует и выглядит просто отлично, и все поведение пока хорошо.Тем не менее, одна вещь, с которой у меня возникают проблемы, - это переводы, которые я делаю на все части пирога.
ТАК, что я делаю: я хочу, чтобы поле n между кусками пирога создавало маржуотодвиньте все части от середины.Это означает, что кусок пирога, обращенный вверх, будет иметь отрицательный перевод.Это, в свою очередь, означает, что холст обрежет часть вершины (например, вершина 14, -2).Еще одна вещь, которую я добавил, это кусочки текста, которые также делают кусочки пирога немного длиннее.См. Изображение для справки.
image
Слева вы можете увидеть проблему отсечения, о которой я говорю, справа вы можете увидеть произвольно переведенную версиютого же самого.
Некоторая вставка кода:
Главное окно XAML:
<controls:PieMenu Radius="100" Padding="10">
<controls:PieMenu.MenuItems>
<controls:PieMenuItem Text="Employment" Brush="#FF33FF" Command="BrowseBack" />
<controls:PieMenuItem Text="General" Brush="#9933FF" Command="BrowseBack" />
<controls:PieMenuItem Text="Internships" Brush="#3333FF" Command="BrowseBack" />
<controls:PieMenuItem Text="Bla" Brush="#3399FF" Command="BrowseBack" />
<controls:PieMenuItem Text="Bla" Brush="#007AF5" Command="BrowseBack" />
</controls:PieMenu.MenuItems>
PieMenu XAML:
<UserControl x:Class="PieControlLibrary.PieMenu"
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:self="clr-namespace:PieControlLibrary"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<!-- <CollectionViewSource x:Name="menuItemCollectionViewSource" Source="{Binding MenuItems, RelativeSource={RelativeSource AncestorType=self:PieMenu}}"/>-->
<Style TargetType="{x:Type ListView}" x:Key="listViewStyle">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<self:PieButton Radius="{Binding Radius, RelativeSource={RelativeSource AncestorType=self:PieMenu}}"
Degrees="{Binding Degrees, RelativeSource={RelativeSource AncestorType=self:PieMenu}}"
Brush="{Binding Brush}"
Command="{Binding Command}"
Text="{Binding Text}"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<ListView x:Name="menuItemsView" ItemsSource="{Binding MenuItems, RelativeSource={RelativeSource AncestorType=self:PieMenu}}" Style="{StaticResource listViewStyle}" />
</Grid>
PieButton (это то, во что преобразованы элементы кругового меню)
<UserControl x:Class="PieControlLibrary.PieButton"
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:control="clr-namespace:PieControlLibrary"
xmlns:TextOnPath="clr-namespace:Petzold.TextOnPath"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
>
<Grid>
<Button HorizontalAlignment="Left" VerticalAlignment="Top" DataContext="{Binding RelativeSource={RelativeSource AncestorType=control:PieButton}}" Command="{Binding Command}">
<Button.Template>
<ControlTemplate>
<Canvas >
<Path Data="{Binding PathData}" Fill="{Binding Brush}" Grid.Row="0" Grid.Column="0" />
<TextOnPath:TextOnPathControl PathFigure="{Binding TextPath}" Text="{Binding Text}" FontFamily="Consolas" FontSize="12" Foreground="Black" FontStretch="Normal" />
</Canvas>
</ControlTemplate>
</Button.Template>
</Button>
</Grid>