2017-02-08 3 views
0

ベースダイアログのコントロールテンプレートを作成しようとしています。ここにコンテンツの上部に表示できる定義済みのボタンが含まれています。問題は、ボタンがコンテンツと適切に積み重なっていないことです。これは、基本ダイアログリソースのコードがオーバーレイされたボタンをベースコントロールからスタックする方法

final result

です:私はこのような何かを得るために期待しています

issue

この

は、私が現在取得しています結果です:

<ControlTemplate x:Key="BaseDialogTemplate" TargetType="{x:Type dialogs:BaseDialog}"> 
    <Grid Background="{TemplateBinding Background}"> 
     <ScrollViewer VerticalScrollBarVisibility="Auto" 
         HorizontalScrollBarVisibility="Auto"> 
      <Grid> 
       <ContentPresenter x:Name="PART_ContentPresenter" 
            Content="{TemplateBinding Content}" /> 
       <Grid HorizontalAlignment="Stretch" 
         VerticalAlignment="Stretch"> 
        <StackPanel x:Name="PART_ButtonStackPanel" 
           Margin="10" 
           HorizontalAlignment="Right" 
           VerticalAlignment="Bottom" 
           Orientation="Horizontal"> 
         <Button x:Name="PART_OkButton" 
           MinWidth="80" 
           Margin="0 0 5 0" 
           Background="Yellow" 
           Content="Base Ok Button" /> 
         <Button x:Name="PART_CancelButton" 
           MinWidth="80" 
           Margin="5 0 5 0" 
           Background="Yellow" 
           Content="Base Cancel Button" /> 
        </StackPanel> 
       </Grid> 
      </Grid> 
     </ScrollViewer> 
    </Grid> 
</ControlTemplate> 

<Style TargetType="{x:Type dialogs:BaseDialog}"> 
    <Setter Property="Foreground" Value="Black" /> 
    <Setter Property="Background" Value="White" /> 
    <Setter Property="Template" Value="{StaticResource BaseDialogTemplate}" /> 
</Style> 

答えて

0

スタックパネルを含むあなたのContentPresenterとグリッドの両方のコンテンツを分離するRowDefinitionsを追加Grid.Row 0トライの一部であり、このような何か:

<ControlTemplate x:Key="BaseDialogTemplate" TargetType="{x:Type dialogs:BaseDialog}"> 
    <Grid Background="{TemplateBinding Background}"> 
     <ScrollViewer VerticalScrollBarVisibility="Auto" 
         HorizontalScrollBarVisibility="Auto"> 
      <Grid> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="*" /> 
        <RowDefinition Height="Auto" />       
       </Grid.RowDefinitions> 
       <ContentPresenter x:Name="PART_ContentPresenter" 
            Content="{TemplateBinding Content}" /> 
       <Grid Grid.Row="1" HorizontalAlignment="Stretch" 
         VerticalAlignment="Stretch"> 
        <StackPanel x:Name="PART_ButtonStackPanel" 
           Margin="10" 
           HorizontalAlignment="Right" 
           VerticalAlignment="Bottom" 
           Orientation="Horizontal"> 
         <Button x:Name="PART_OkButton" 
           MinWidth="80" 
           Margin="0 0 5 0" 
           Background="Yellow" 
           Content="Base Ok Button" /> 
         <Button x:Name="PART_CancelButton" 
           MinWidth="80" 
           Margin="5 0 5 0" 
           Background="Yellow" 
           Content="Base Cancel Button" /> 
        </StackPanel> 
       </Grid> 
      </Grid> 
     </ScrollViewer> 
    </Grid> 
</ControlTemplate> 

<Style TargetType="{x:Type dialogs:BaseDialog}"> 
    <Setter Property="Foreground" Value="Black" /> 
    <Setter Property="Background" Value="White" /> 
    <Setter Property="Template" Value="{StaticResource BaseDialogTemplate}" /> 
</Style> 
+0

はご回答いただきありがとうございます。私は前にこのようなことをやろうとしましたが、私が望む結果に満足していませんでした。ボタンはコンテンツの上にあるように表示されません(コンテンツをオーバーレイしません)。 –

+0

実際には、これは私の最善の選択肢であると思います。私はこれを答えにするつもりです。ありがとうございました –

関連する問題