0
我有這個XAML,我試圖讓TabItem的內容滾動(沒有成功)。Silverlight TabItem content not scrolling
<ex:TabControl>
<ex:TabItem Header="General">
<ContentPresenter Content="{Binding }" ContentTemplate="{StaticResource tabMenuItem}" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" />
</ex:TabItem>
<ex:TabItem Header="Prices (Item)">
<ScrollViewer VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Auto">
<ContentPresenter Content="{Binding NonModifierPricesView}" ContentTemplate="{StaticResource tabMenuItemPrices}" />
</ScrollViewer>
</ex:TabItem>
</ex:TabControl>
當我的TabControl得到調整,讓TabItem的是太小,無法顯示全部內容,不顯示滾動條。我在某處做錯了什麼?
編輯:爲tabMenuItemPrices
<DataTemplate x:Key="tabMenuItemPrices">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*" />
<RowDefinition Height="Auto"/>
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
</Grid.ColumnDefinitions>
<TextBlock Text="Prices (in order of priority)" />
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<ListBox HorizontalAlignment="Stretch" Margin="{StaticResource DefaultMargin}" x:Name="lstMenuItemPrices" SelectionMode="Single"
ItemsSource="{Binding }" ItemTemplate="{StaticResource MenuItemPriceDataTemplate}" Height="140" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<cmd:EventToCommand Command="{Binding DataContext.UpdateSelectedTaxGroupsCommand, ElementName=Editor}" CommandParameter="{Binding SelectedItem, ElementName=lstMenuItemPrices}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ListBox>
<StackPanel VerticalAlignment="Center" Grid.Column="1" >
<Button Content="Move Up" HorizontalAlignment="Center" Margin="2" IsEnabled="{Binding SelectedIndex, Converter={StaticResource MinimumIntegerToBooleanConverter}, ConverterParameter=0, ElementName=lstMenuItemPrices, Mode=OneWay}" />
<Button Content="Move Down" HorizontalAlignment="Center" Margin="2" IsEnabled="{Binding SelectedIndex, Converter={StaticResource MinimumIntegerToBooleanConverter}, ConverterParameter=0, ElementName=lstMenuItemPrices, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.ColumnSpan="2">
<Button HorizontalAlignment="Left" Margin="2" Content="New Price" Command="{Binding DataContext.AddPriceCommand, ElementName=Editor}" />
<Button Content="Remove Price" HorizontalAlignment="Left" Margin="2" Command="{Binding DataContext.RemovePriceCommand, ElementName=Editor}" CommandParameter="{Binding SelectedItem, ElementName=lstMenuItemPrices}"
IsEnabled="{Binding SelectedIndex, Converter={StaticResource MinimumIntegerToBooleanConverter}, ConverterParameter=0, ElementName=lstMenuItemPrices, Mode=OneWay}"/>
</StackPanel>
</Grid>
<TextBlock Text="Selected Price" Grid.Row="2" />
<Grid Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<CheckBox Content="Amount Includes Tax" d:LayoutOverrides="Width, Height" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center"
IsChecked="{Binding SelectedItem.DTO.AmountIncludesTax, Mode=TwoWay, ElementName=lstMenuItemPrices}" Grid.ColumnSpan="3"/>
<TextBlock HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Text="Amount" Grid.Row="1"/>
<TextBlock Text="Cost" d:LayoutOverrides="Width, Height, GridBox" HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Row="2"/>
<TextBlock HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Text="Points" Grid.Row="3"/>
<TextBlock HorizontalAlignment="Right" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Text="Interface ID" Grid.Row="4"/>
<TextBox VerticalAlignment="Center" Grid.Row="1" Grid.Column="1" Margin="{StaticResource DefaultMargin}"
Text="{Binding SelectedItem.DTO.Amount, Mode=TwoWay, ElementName=lstMenuItemPrices, Converter={StaticResource DecimalToMoneyStringConverter}}" />
<CheckBox Content="Open" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Row="1" Grid.Column="2"
IsChecked="{Binding SelectedItem.DTO.IsOpenAmount, Mode=TwoWay, ElementName=lstMenuItemPrices}"/>
<TextBox Text="{Binding SelectedItem.DTO.Cost, Converter={StaticResource DecimalToMoneyStringConverter}, Mode=TwoWay, ElementName=lstMenuItemPrices}" TextWrapping="Wrap"
Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" d:LayoutOverrides="GridBox" Grid.Column="1" Grid.Row="2"/>
<CheckBox Content="Inherit" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Column="2" Grid.Row="2"
IsChecked="{Binding SelectedItem.DTO.CostOverride, Converter={StaticResource CostToBooleanConverter}, Mode=TwoWay, ElementName=lstMenuItemPrices}" />
<TextBox Text="{Binding SelectedItem.DTO.PointsEarned, Converter={StaticResource IntegerToStringConverter}, Mode=TwoWay, ElementName=lstMenuItemPrices}" TextWrapping="Wrap"
Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Column="1" Grid.Row="3"
IsEnabled="{Binding SelectedItem.DTO.PointsEarnedInherited, Converter={StaticResource ReverseBooleanConverter}, ElementName=lstMenuItemPrices}"/>
<CheckBox Content="Inherit" Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Grid.Column="2" Grid.Row="3"
IsChecked="{Binding SelectedItem.DTO.InheritPointsEarned, Mode=TwoWay, ElementName=lstMenuItemPrices}" />
<TextBox Margin="{StaticResource DefaultMargin}" Grid.Column="1" Grid.Row="4"
Text="{Binding SelectedItem.DTO.InterfaceID, Mode=TwoWay, ElementName=lstMenuItemPrices}" />
<CheckBox Margin="{StaticResource DefaultMargin}" VerticalAlignment="Center" Content="Inherit tax from class" HorizontalAlignment="Left"
IsChecked="{Binding SelectedItem.DTO.InheritTaxes, Mode=TwoWay, ElementName=lstMenuItemPrices}" Grid.Row="5" Grid.ColumnSpan="3" />
<ListBox Margin="{StaticResource DefaultMargin}" Grid.Row="6" Grid.ColumnSpan="3" SelectionMode="Multiple" ItemsSource="{Binding DataContext.Repository.TaxGroups, ElementName=Editor}"
IsEnabled="{Binding SelectedItem.DTO.InheritTaxes, Converter={StaticResource BooleanToEnabledConverter}, ElementName=lstMenuItemPrices, ConverterParameter=false}">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem" >
<Setter Property="Margin" Value="2, 2, 2, 0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="Transparent">
<CheckBox IsChecked="{Binding Path=IsSelected, Mode=TwoWay}"
Content="{Binding DTO.Name}" Padding="5,0,10,0" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<cmd:EventToCommand Command="{Binding SelectedItem.AddTaxGroupCommand, ElementName=lstMenuItemPrices}" CommandParameter="{Binding DTO.ID}" />
</i:EventTrigger>
<i:EventTrigger EventName="Unchecked">
<cmd:EventToCommand Command="{Binding SelectedItem.RemoveTaxGroupCommand, ElementName=lstMenuItemPrices}" CommandParameter="{Binding DTO.ID}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
</Grid>
</Grid>
</DataTemplate>
已過帳。它看起來像滾動查看器溢出TabItem的底部,因爲我沒有看到向下箭頭。 – 2012-03-01 15:51:12
它沒有工作。調整TabControl的大小仍然只是將scrollviewer推出底部。對我來說,它看起來像TabItem控件不告訴它的孩子他們需要什麼大小。 – 2012-03-01 16:07:27
奇怪......我無法重現您的問題。 TabControl父級XAML是什麼樣的? – 2012-03-01 16:10:45