用户控件中的滑块不会移动

时间:2015-02-28 05:55:41

标签: windows-phone-8.1 winrt-xaml

我在用户控件中有一个滑块。测试时,如果滑块保持在用户控件内但在其外部工作,滑块将不会移动。是否需要一些能够使其发挥作用的东西?

用户控件的XAML:

        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="60"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="4,0,3,0" Grid.RowSpan="1">
                <TextBlock Text="15 mins" VerticalAlignment="Center" FontSize="16" Margin="0,-11,0,0" TextLineBounds="Tight" Foreground="White"/>
                <Slider Foreground="White" SmallChange="50" TickFrequency="50" LargeChange="50" Background="#BFFFFFFF" Value="50" Margin="5,0" VerticalAlignment="Center" Width="250" StepFrequency="50" Maximum="100" ValueChanged="Slider_ValueChanged"/>
                <TextBlock Text="1 hour" VerticalAlignment="Center" FontSize="16" Margin="0,-11,0,0" TextLineBounds="Tight" Foreground="White"/>
            </StackPanel>
            <ListBox x:Name="TimesList" DataContext="{Binding}" Background="{x:Null}" Foreground="White">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid Width="365" DataContext="{Binding}">
                            <TextBlock Foreground="White" Text="{Binding}" HorizontalAlignment="Stretch" FontSize="29.333"/>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <Border Grid.RowSpan="2" BorderBrush="#B2FFFFFF" BorderThickness="2,0,2,2" Padding="0" Margin="-5,0,-5,-5"/>
        </Grid>

1 个答案:

答案 0 :(得分:0)

我发现60像素的高度不足以Slider控制。这就是为什么它不起作用。但是解决它的方法很简单。您可以选择适合您需求的任何产品。

选项1
将第一行定义高度更改为Auto。因此Grid将与Slider控件一样高。这是84像素。

<Grid.RowDefinitions>
    <RowDefinition Height="Auto"/>
    <RowDefinition Height="Auto"/>
</Grid.RowDefinitions>

选项2
使用Grid布局的方式使其与StackPanel几乎相同。因此,您也可以将此Grid替换为StackPanel

选项3
您可以更改Sldier的边距以适合60像素的高度。将下边距设置为-24。

<Slider Foreground="White" SmallChange="50" TickFrequency="50" LargeChange="50" Background="#BFFFFFFF" Value="50" Margin="5,0,5,-24" VerticalAlignment="Center" Width="250" StepFrequency="50" Maximum="100" ValueChanged="Slider_ValueChanged"/>
相关问题