WPF的滚动条问题

时间:2015-10-07 08:52:12

标签: c# .net wpf xaml

在下面的XAML中我有两个问题,第一个是尽管它仍然显示主滚动查看器上禁用水平滚动条,但第二个是我在文本框(注释)上设置了一个样式以显示垂直滚动条但是它不显示

<UserControl x:Class="VTUK.Gemini.Contacts.ContactsDetails"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
             xmlns:views="clr-namespace:VTUK.Gemini.Contacts"
             mc:Ignorable="d" 
             d:DesignHeight="1200" d:DesignWidth="1200">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/VTUK.Gemini.Infrastructure;component/Styles/Brushes.xaml"/>
                <ResourceDictionary Source="pack://application:,,,/VTUK.Gemini.Infrastructure;component/Styles/CommonStyles.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <DataTemplate x:Key="ContactsReadOnlyTemplate">
                <Grid Name="Grid">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <StackPanel Name="HeaderPanel" Orientation="Horizontal">
                        <Border BorderThickness="2" BorderBrush="{StaticResource Windows8BlueBrush}" Margin="5" >
                            <!--Phone3 is here as a temporary value--> 
                            <telerik:RadTransitionControl Margin="5" Content="{Binding Phone3, FallbackValue='pack://application:,,,/VTUK.Gemini.Infrastructure;component/Images/businessperson2.png', Converter={StaticResource ImageSourceToBitmapConverter}}" Duration="0:0:1" IsTabStop="False">
                                <telerik:RadTransitionControl.Transition>
                                    <!--<telerik:MotionBlurredZoomTransition/>-->
                                    <telerik:FlipWarpTransition/>
                                </telerik:RadTransitionControl.Transition>
                                <telerik:RadTransitionControl.ContentTemplate>
                                    <DataTemplate>
                                        <Image Source="{Binding .}"  Width="64" Height="64" />
                                    </DataTemplate>
                                </telerik:RadTransitionControl.ContentTemplate>
                            </telerik:RadTransitionControl>
                        </Border>

                    </StackPanel>

                    <ScrollViewer x:Name="ScrollViewer" Width="{Binding ElementName=LayoutRoot, Path=ActualWidth}" Grid.Row="1" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" BorderThickness="0">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="10" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" MinHeight="45" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="45" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                                <RowDefinition Height="Auto" MinHeight="28" />
                            </Grid.RowDefinitions>

                            <TextBlock Text="DISPLAY NAME" Style="{StaticResource Heading14}" />
                            <TextBlock Text="TITLE" Style="{StaticResource Heading14}" Grid.Row="1" Grid.Column="0" />
                            <TextBlock Text="FORENAME" Style="{StaticResource Heading14}" Grid.Row="2" Grid.Column="0"/>
                            <TextBlock Text="SURNAME" Style="{StaticResource Heading14}" Grid.Row="3" Grid.Column="0"/>
                            <TextBlock Text="HOUSE NAME / NO." Style="{StaticResource Heading14}" Grid.Row="4" Grid.Column="0"/>
                            <TextBlock Text="ADDRESS1" Style="{StaticResource Heading14}" Grid.Row="5" Grid.Column="0"/>
                            <TextBlock Text="ADDRESS2" Style="{StaticResource Heading14}" Grid.Row="6" Grid.Column="0"/>
                            <TextBlock Text="TOWN" Style="{StaticResource Heading14}" Grid.Row="7" Grid.Column="0"/>
                            <TextBlock Text="COUNTY" Style="{StaticResource Heading14}" Grid.Row="8" Grid.Column="0"/>
                            <TextBlock Text="COUNTRY" Style="{StaticResource Heading14}" Grid.Row="9" Grid.Column="0"/>
                            <TextBlock Text="POSTCODE" Style="{StaticResource Heading14}" Grid.Row="10" Grid.Column="0"/>
                            <TextBlock Text="EMAIL" Style="{StaticResource Heading14}" Grid.Row="11" Grid.Column="0"/>
                            <TextBlock Text="PHONE !" Style="{StaticResource Heading14}" Grid.Row="12" Grid.Column="0"/>
                            <TextBlock Text="PHONE 2" Style="{StaticResource Heading14}" Grid.Row="13" Grid.Column="0"/>
                            <TextBlock Text="PHONE 3" Style="{StaticResource Heading14}" Grid.Row="14" Grid.Column="0"/>
                            <TextBlock Text="URL" Style="{StaticResource Heading14}" Grid.Row="15" Grid.Column="0"/>
                            <TextBlock Text="NOTES" Style="{StaticResource Heading14}" Grid.Row="16" Grid.Column="0" VerticalAlignment="Top"/>

                            <TextBlock Text="{Binding DisplayName}" TextWrapping="Wrap" FontSize="22" FontWeight="DemiBold" Grid.Row="0" Grid.Column="2"  VerticalAlignment="Center" />
                            <TextBlock Text="{Binding Title}" Style="{StaticResource Text14}"  TextWrapping="Wrap" Grid.Column="2" Grid.Row="1" />
                            <TextBlock Text="{Binding Forename}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="2" />
                            <TextBlock Text="{Binding Surname}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="3" />
                            <TextBlock Text="{Binding HouseNameNo}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="4" />
                            <TextBlock Text="{Binding Address1}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="5" />
                            <TextBlock Text="{Binding Address2}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="6" />
                            <TextBlock Text="{Binding Town, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="7" />
                            <TextBlock Text="{Binding County, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="8" />
                            <TextBlock Text="{Binding Country, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="9" />
                            <TextBlock Text="{Binding Postcode, Converter={StaticResource StringToUpperCaseConverter}}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="10" />
                            <TextBlock Text="{Binding Email}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="11" />
                            <TextBlock Text="{Binding Phone1}" TextWrapping="Wrap" FontSize="22" FontWeight="DemiBold"  Grid.Column="2" Grid.Row="12" VerticalAlignment="Center" />
                            <TextBlock Text="{Binding Phone2}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="13" />
                            <TextBlock Text="{Binding Phone3}" Style="{StaticResource Text14}" TextWrapping="Wrap" Grid.Column="2" Grid.Row="14" />

                            <TextBlock x:Name="URLContainer" Text="http://www.google.com" Visibility="Collapsed" />
                            <telerik:RadButton x:Name="linkButton"
                                           VerticalAlignment="Center"
                                           Margin="0"
                                           Content="{Binding Text, ElementName=URLContainer}"
                                           Grid.Column="2" Grid.Row="15" 
                                           Style="{StaticResource HyperlinkStyleButton14}"
                                           Command="{Binding NavigateToUrlCommand}" CommandParameter="{Binding Text, ElementName=URLContainer}" 
                                           DataContext="{Binding DataContext, RelativeSource={RelativeSource AncestorType=views:ContactsContent, AncestorLevel=1}}" />

                            <TextBox Grid.Column="2"  Grid.Row="16"  
                                 Text="{Binding ContactNotes}"
                                 Style="{DynamicResource CustomTextBoxStyle}" />
                                     <!--Visibility="{Binding ContactNotes, Converter={StaticResource StringToVisibilityConverter}}" />-->
                        </Grid>
                    </ScrollViewer>
                </Grid>
            </DataTemplate>
        </ResourceDictionary>
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <telerik:RadDataForm x:Name="DataForm"
                             ItemsSource="{Binding Contacts}"
                             CommandButtonsVisibility="Cancel,Commit" 
                             AutoGenerateFields="False"
                             ValidationSummaryVisibility="Visible"
                             LabelPosition="Above"
                             ReadOnlyTemplate="{StaticResource ContactsReadOnlyTemplate}" 
                             VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" />

        <StackPanel HorizontalAlignment="Right" VerticalAlignment="Top" Orientation="Horizontal">
            <telerik:RadButton RenderTransformOrigin="0.5,0.5"  Margin="0,0,40,0" Tag="ADD"
                               Command="telerik:RadDataFormCommands.AddNew" CommandTarget="{Binding ElementName=DataForm}">
                <Path Stretch="None" Data="M6,0 L10,0 L10,6 L16,6 L16,10 L10,10 L10,16 L6,16 L6,10 L0,10 L0,6 L6,6 z" 
                      SnapsToDevicePixels="True" />
            </telerik:RadButton>
            <telerik:RadButton Command="telerik:RadDataFormCommands.BeginEdit" CommandTarget="{Binding ElementName=DataForm}" Tag="EDIT">
                <Path Stretch="Fill" Data="F1 M233.5498,613.749 C233.9048,613.662,233.9828,613.379,233.7238,613.123 L232.1378,611.544 C231.8808,611.288,231.5968,611.367,231.5098,611.718L230.9968,613.784C230.9088,614.139,231.1258,614.355,231.4808,614.267z M249.4978,595.808C247.7348,594.047,245.9968,595.404,245.9968,595.404C245.7078,595.627,245.2668,596.019,245.0118,596.269C244.7588,596.521,244.7638,596.939,245.0198,597.196L248.1078,600.281C248.3648,600.54,248.7828,600.544,249.0388,600.29C249.2918,600.036,249.6808,599.594,249.9038,599.307C249.9038,599.307,251.2638,597.572,249.4978,595.808 M237.2018,612.109C236.9458,612.369,236.5228,612.369,236.2668,612.109L233.1778,609.025C232.9208,608.768,232.9208,608.349,233.1778,608.09L243.0538,598.228C243.3108,597.971,243.7318,597.971,243.9898,598.228L247.0738,601.312C247.3328,601.571,247.3328,601.993,247.0738,602.248z" 
                      Height="16" Width="16"
                      SnapsToDevicePixels="True" /> 
            </telerik:RadButton>
        </StackPanel>

        <telerik:RadBusyIndicator IsIndeterminate="True" 
                                  IsBusy="{Binding IsBusy}" DisplayAfter="0:0:0.2"
                                  telerik:AnimationManager.IsAnimationEnabled="True"/>
    </Grid>
</UserControl>




<!-- Texybox with scrollviewer-->
    <Style x:Key="CustomTextBoxStyle" TargetType="TextBox">
        <Setter Property="Background" Value="{x:Null}" />
        <Setter Property="BorderBrush" Value="{x:Null}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="TextWrapping" Value="Wrap" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="FontSize" Value="14" />
        <Setter Property="Margin" Value="0" />
        <Setter Property="Padding" Value="0" />
        <Setter Property="IsReadOnly" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                    <Grid x:Name="RootElement" UseLayoutRounding="True">
                        <ScrollViewer  x:Name="PART_ContentHost" 
                                       Padding="{TemplateBinding Padding}"
                                       Foreground="{TemplateBinding Foreground}" 
                                       Background="{x:Null}"
                                       BorderBrush="{x:Null}"
                                       BorderThickness="0"
                                       Margin="0" 
                                       VerticalScrollBarVisibility="Visible" />

                   </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

0 个答案:

没有答案