导航按钮在WPF中无法正常工作

时间:2018-08-03 07:29:52

标签: c# wpf data-binding wpf-controls wpfdatagrid

Chef Summary 我为UI编写了以下代码。

附加的图像是将使用以下代码生成的UI。我的导航按钮无法正常工作。我需要从一页导航到另一页。它正在运行,但是在小屏幕上却无法正常工作。

BorderThickness="3" BorderBrush="Gray" WindowStartupLocation="CenterScreen" Icon="../Images/C_Transparent.ico" FontFamily="Tahoma">

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Themes/MenumateTheme.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <local:PercentageConverter x:Key="percentageConverter" />
    </ResourceDictionary>
</Window.Resources>

<Grid Name="OuterGrid">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width=".60*"/>
        <ColumnDefinition Width=".4*"/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height=".1*"/>
        <RowDefinition Height=".9*"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0" Grid.Column="0" Background="#F09422" >
        <Label FontSize="24"   Content="Items Summary" VerticalAlignment="Center" HorizontalAlignment="Center" Foreground="White" />
    </Grid>
    <Grid Grid.Row="0" Grid.Column="1" HorizontalAlignment="Stretch">
        <!--<Grid Grid.Column="1" HorizontalAlignment="Stretch">-->
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width=".20*"/>
            <ColumnDefinition Width=".15*"/>
            <ColumnDefinition Width=".15*"/>
            <ColumnDefinition Width=".15*"/>
            <ColumnDefinition Width=".15*"/>
            <ColumnDefinition Width=".20*"/>
        </Grid.ColumnDefinitions>
        <Button Style="{StaticResource FunctionButtonStyle}"  Command="{Binding AutoUpdateCommand}" Grid.Column="0" Content="Update UI" Background="#FFF09422" />
        <Button Style="{StaticResource NavigationButtonStyle}" Grid.Column="1" Command="{Binding NavigateLeftCommand}"
                    Name="LeftNavigationButton">
            <Path Data="M 0 0 L 0 40 L5 40 L 5 20 L 40 40 L 40 0 L 5 20 L 5 0  Z"/>
        </Button>
        <Button Style="{StaticResource NavigationButtonStyle}" Grid.Column="2" Command="{Binding NavigateBackwardCommand}"
                    Name="BackwardNavigationButton">
            <Path Data="M 0 20 L 40 40 L 40 0 Z"/>
        </Button>
        <Button Style="{StaticResource NavigationButtonStyle}" Grid.Column="3" Command="{Binding NavigateForwardCommand}"
                    Name="ForwardNavigationButton">
            <Path Data="M 0 0 L 0 40 L 40 20 Z"/>
        </Button>
        <Button Style="{StaticResource NavigationButtonStyle}" Grid.Column="4" Command="{Binding NavigateRightCommand}"  
                    Name="RightNavigationButton">
            <Path Data="M 0 0 L 0 40 L 35 20 L 35 40 L 40 40 L 40 0 L 35 0 L 35 20 Z"/>
        </Button>
        <Button Style="{StaticResource FunctionButtonStyle}" Grid.Column="5" Background="#FFF09422"  Command="{Binding CloseCommand}">Close</Button>
    </Grid>
    <Grid Grid.Row="1" Grid.ColumnSpan="2">
        <ListBox x:Name="ItemSummaryList"  ScrollViewer.HorizontalScrollBarVisibility="Hidden">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel Orientation="Vertical"  Height="{Binding Converter={StaticResource   percentageConverter}, ElementName=ItemSummaryList, Path=ActualHeight, ConverterParameter=.99}">
                    </WrapPanel>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ItemTemplate>
                <DataTemplate >
                    <StackPanel Name="S1" Orientation="Vertical" Width="{Binding Converter={StaticResource   percentageConverter}, ElementName=ItemSummaryList, Path=ActualWidth, ConverterParameter=0.5}">
                        <Border CornerRadius="1" BorderThickness="2" BorderBrush="#C4D3C4" Background="#C4D3C4" Margin="0,2,0,2">
                            <Label FontSize="34" Content="{Binding Path=DataContext, RelativeSource={RelativeSource Self}}" VerticalAlignment="Center">
                            </Label>
                        </Border>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
    <Label Grid.Row="2" Grid.Column="0" Style="{StaticResource FormLabel}" Foreground="Red" Content="{Binding StatusText}"></Label>
</Grid>

我想从一页导航到另一页。

为了向后导航,我写了以下内容。

private void Backward(object sender) 
{ 
    var scroller = FindVisualChild<ScrollViewer>(ItemSummaryList);  
    ItemOffset = System.Convert.ToDouble(System.Windows.SystemParameters.PrimaryScreenWidth); 
    scroller.ScrollToHorizontalOffset(scroller.HorizontalOffset - ItemOffset); 
} 

0 个答案:

没有答案