powered by simpleCommunicator - 2.0.51     © 2025 Programmizd 02
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Смещение подменю
3 сообщений из 3, страница 1 из 1
Смещение подменю
    #37391729
maratoss
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Делаю фильтр, для отображения используется контекстное меню.
В 5-ом Силверлайте смещение под-меню работает нормально.
В 4-ом вылазит в верху (видимо смещается относительно RootVisual)

Сделал так, код при открытии под-меню, задаю смещение относительно RootVisual:
Код: plaintext
1.
2.
3.
4.
5.
6.
             //Если SL 4-й версии
            if (Environment.Version.ToString()[0] == '4')
            {
                var sourceOffset = this.TransformToVisual(Application.Current.RootVisual).Transform(new Point(0, 0));
                popup.HorizontalOffset = sourceOffset.X + this.RenderSize.Width;
                popup.VerticalOffset = sourceOffset.Y;
            }

Но теперь первое подменю вылазит нормально, второе ниже чем нужно.
Как правильно указать смещение?

xaml Sub-меню:

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
<Style TargetType="local:SuperMenuItem">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="Transparent"/>
        <Setter Property="Padding" Value="4,3,2,3"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:SuperMenuItem">
                    <Grid x:Name="PART_RootGrid">

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Presenter"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Unfocused"/>
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Bg"/>
                                        <ColorAnimation Duration="0" To="#40FFFFFF" Storyboard.TargetProperty="(Shape.Stroke).(SolidColorBrush.Color)" Storyboard.TargetName="InnerBorder"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle Fill="{TemplateBinding Background}" RadiusY="2" RadiusX="2" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="1"/>
                        <Rectangle x:Name="Bg" Opacity="0" RadiusY="2" RadiusX="2" Stroke="#8071CBF1" StrokeThickness="1">
                            <Rectangle.Fill>
                                <LinearGradientBrush EndPoint="0,1" StartPoint="0,0">
                                    <GradientStop Color="#34C5EBFF" Offset="0"/>
                                    <GradientStop Color="#3481D8FF" Offset="1"/>
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle x:Name="InnerBorder" Margin="1" RadiusY="2" RadiusX="2" Stroke="Transparent"/>

                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition MinWidth="24" Width="Auto" />
                                <ColumnDefinition Width="4" />
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="17" />
                            </Grid.ColumnDefinitions>

                            <ContentPresenter Content="{TemplateBinding Icon}" Margin="1" VerticalAlignment="Center"/>
                            <ContentPresenter x:Name="Presenter" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Grid.Column="2" Margin="{TemplateBinding Padding}" />
                            <Path x:Name="PART_RightIcon" Grid.Column="3" Data="M 0,0 L 4,3.5 L 0,7 Z" Fill="Black" Margin="4,0,0,0" VerticalAlignment="Center" Visibility="{TemplateBinding HasSubItems}" />
                            <!--<Path x:Name="Glyph" Data="M 0,5.1 L 1.7,5.2 L 3.4,7.1 L 8,0.4 L 9.2,0 L 3.3,10.8 Z"
                                  Fill="#0C12A1" FlowDirection="LeftToRight" Height="11" Width="9"/>-->
                        </Grid>

                        <Popup x:Name="PART_Popup" HorizontalOffset="{TemplateBinding ActualWidth}" IsOpen="{TemplateBinding IsSubmenuOpen}" Margin="-4,0,0,0">
                            <ContentControl x:Name="SubMenuBorder">
                                <ContentControl.Template>
                                    <ControlTemplate>
                                        <Grid Background="#FFF5F5F5">
                                            <Rectangle Fill="#F1F1F1" HorizontalAlignment="Left" RadiusY="2" RadiusX="2" Width="28" />
                                            <Rectangle Fill="#E2E3E3" HorizontalAlignment="Left" Width="1" Margin="30,0,0,0" />
                                            <Rectangle Fill="White" HorizontalAlignment="Left" Width="1" Margin="31,0,0,0" />
                                            <ContentPresenter Grid.ColumnSpan="2" Margin="1,0" />
                                        </Grid>
                                    </ControlTemplate>
                                </ContentControl.Template>
                                <ScrollViewer x:Name="SubMenuScrollViewer" VerticalScrollBarVisibility="Auto" Padding="0">
                                    <Grid>
                                        <Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
                                            <Rectangle Fill="#FFF5F5F5" Height="{Binding ActualHeight, ElementName=SubMenuBorder}" Width="{Binding ActualWidth, ElementName=SubMenuBorder}" />
                                        </Canvas>
                                        <ItemsPresenter x:Name="ItemsPresenter" Margin="2" />
                                    </Grid>
                                </ScrollViewer>
                            </ContentControl>
                        </Popup>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
...
Рейтинг: 0 / 0
Смещение подменю
    #37391732
maratoss
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
автор //Если SL 4-й версии
if (Environment.Version.ToString()[0] == '4')
{
var sourceOffset = this.TransformToVisual(Application.Current.RootVisual).Transform(new Point(0, 0));
popup.HorizontalOffset = sourceOffset.X + this.RenderSize.Width;
popup.VerticalOffset = sourceOffset.Y;
}

popup - это PART_Popup (на всякий случай)
...
Рейтинг: 0 / 0
Смещение подменю
    #37393435
maratoss
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Оказалось смещения для подменю было уже задано,
нужно было только указать начало координат родителя подменю.
popup.VerticalOffset = ((FrameworkElement)this.Parent).TransformToVisual(Application.Current.RootVisual).Transform(new Point(0, 0)).Y;
...
Рейтинг: 0 / 0
3 сообщений из 3, страница 1 из 1
Форумы / WPF, Silverlight [игнор отключен] [закрыт для гостей] / Смещение подменю
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]