none
custom control en menu qu se deslice RRS feed

  • Pregunta

  • Buenas tardes, logre hacer un template para un boton que consta de varios campos y son un texto superior, un texto imferior, el content, el fondo cambia con el mouse, Pero me atore al momento de querer hacer un menu que se pueda deslizar, en winform lo tengo y capturo los eventos del mouse, tambien tengu un List<Boton> para designar la cantidad de botones a utilizar, una clase con las propiedades del boton e u n List<Clase> que determina los elementos que tendra para deslizarse

    y con este codigo se mueven yasea verticalmento u horizontalmente

    public static void Moves(List<SlideMenuData> lista, Orientacion orientacion, ref Point Bus1, Point Bus2, ref int pos,int Incremento, ref List<ButtonX> List_b1)
            {
                int Max = 0;
                if (lista != null)
                {
                    if (lista.Count > List_b1.Count)
                    {
                        for (int i = 0; i < lista.Count; i++)
                        {
                            if ((Max + List_b1.Count) < lista.Count )
                            {
                                Max = Max + Incremento;
                            }
                            else
                            {  break; }
                        }
                        
                        switch (orientacion)
                        {
                            case Orientacion.Vertical:
                                if (Bus1.Y > Bus2.Y)
                                {
                                    if ((pos + List_b1.Count) <= (lista.Count()))//-1
                                    {
                                        if ((Bus1.Y - Bus2.Y) >= List_b1[0].Size.Height)
                                        {
                                            Bus1 = Bus2;
                                            if (pos < Max)//aqui
                                                pos = pos + Incremento;
                                            LlenaBotonesX(lista, pos, ref List_b1);
                                        }
                                    }
                                }
                                if (Bus1.Y < Bus2.Y)
                                {
                                    if (pos != 0)
                                    {
                                        if ((Bus2.Y - Bus1.Y) >= List_b1[0].Size.Height)
                                        {
                                            Bus1 = Bus2;
                                            if (pos - Incremento > 0)
                                                pos = pos - Incremento;
                                            else
                                                pos = 0;
                                            LlenaBotonesX(lista, pos, ref List_b1);
                                        }
                                    }
                                }
                                break;
                            case Orientacion.Horisontal:
                                if (Bus1.X > Bus2.X)
                                {
                                    if ((pos + List_b1.Count) <= (lista.Count()))//-1
                                    {
                                        if ((Bus1.X - Bus2.X) >= List_b1[0].Size.Width)
                                        {
                                            Bus1 = Bus2;
                                            if (pos<Max)//aqui
                                                pos = pos + Incremento;
                                            
                                            LlenaBotonesX(lista, pos, ref List_b1);                                        
                                        }
                                    }
                                }
                                if (Bus1.X < Bus2.X)
                                {
                                    if (pos != 0)
                                    {
                                        if ((Bus2.X - Bus1.X) >= List_b1[0].Size.Width)
                                        {
                                            Bus1 = Bus2;
                                            if (pos - Incremento > 0)
                                                pos = pos - Incremento;
                                            else
                                                pos = 0;
                                            LlenaBotonesX(lista, pos, ref List_b1);
                                        }
                                    }
                                }
                                break;
                            default:
                                break;
                        }
                        
                    }
                }
            }

     y funciona perfecto en win forms pero en wpf no se como llegar a esto

    y el codigo del template seris este

    <Window.Resources>
            <ImageBrush x:Key="RO1"
                 ImageSource="/Images/BOTON 1.png" />
            <ImageBrush x:Key="RO2"
                 ImageSource="/Images/BOTON 2.png" />
            <ImageBrush x:Key="RO3"
                 ImageSource="/Images/BOTON 4.png" />
            <ImageBrush x:Key="RO4"
                 ImageSource="/Images/BOTON 3.png" />

            <ControlTemplate TargetType="Button" x:Key="imageRoll"  >
                <Grid Name="gridy" Background="{StaticResource RO1}" Margin="3" >

                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <Image x:Name="FrontImage"  Grid.Column="2" Grid.ColumnSpan="4" Grid.Row="1" Grid.RowSpan="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
                    <ContentControl  Grid.Column="1" Grid.ColumnSpan="6" Grid.Row="5" Grid.RowSpan="2"  >
                        <Viewbox>
                            <TextBlock Text="{TemplateBinding Content}"  FontWeight="Bold"  />
                        </Viewbox>
                    </ContentControl>
                    <ContentControl Grid.Column="1" Grid.ColumnSpan="3" Grid.Row="0" Margin="1" HorizontalAlignment="Left" VerticalAlignment="Stretch" >
                        <Viewbox   >
                            <TextBlock x:Name="Upp" Text="" FontWeight="Bold" />
                        </Viewbox>
                    </ContentControl>
                    <ContentControl  Grid.Column="4" Grid.ColumnSpan="3" Grid.Row="7" Margin="1" HorizontalAlignment="Right" VerticalAlignment="Stretch" >
                        <Viewbox>
                            <TextBlock x:Name="Dwnn" Text=""  FontWeight="Bold" />
                        </Viewbox>
                    </ContentControl>
                </Grid>

                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="gridy" Property="Background"
                                                    Value="{StaticResource RO2}" />
                    </Trigger>

                    <Trigger Property="IsPressed" Value="True">
                        <Setter TargetName="gridy" Property="Background"
                                                    Value="{StaticResource RO3}" />
                    </Trigger>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter TargetName="gridy" Property="Background"
                                                    Value="{StaticResource RO4}" />
                    </Trigger>

                </ControlTemplate.Triggers>

            </ControlTemplate>
        </Window.Resources>

    como le hago para lograr hacerlo um List<de template> y poder  usarlo

    domingo, 20 de mayo de 2018 19:32