none
UserControl is larger in Height than MainWindow RRS feed

  • Вопрос

  • I'm making a usercontrol with the size of an A4 paper(96DPI) and that's H:1123 x W:794

    While the MainWindow's Height is H:1000

    So when i run the App, the bottom portion or the UserControl is neither visible nor Printable.

    Any idea how to fix this ? i want the UserControl to be visible when i run the App. by Shrinking the view of it i'm assuming.

    and the Printer to Print the whole H:1123 and not only the H:1000 of the MainWindow

    Thanks!

    Here is the UserControl XAML

    <UserControl x:Class="MyApp.Invoices" 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:local="clr-namespace:MyApp.Views" mc:Ignorable="d" d:DesignHeight="1123" d:DesignWidth="794" Loaded="UserControl_Loaded"> <Grid> <Grid Name="print"> <Grid.RowDefinitions> <RowDefinition Height="1*"/> <RowDefinition Height="1*"/> <RowDefinition Height="3*"/> <RowDefinition Height="4*"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> </Grid> </Grid>

    </UserControl>

    Here is the MainWindow XAML

    <Window x:Class="MyApp.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:local="clr-namespace:MyApp"
            xmlns:viewmodels="clr-namespace:MyApp.ViewModels"
            xmlns:views="clr-namespace:MyApp.Views"
            mc:Ignorable="d"
            Title="MainWindow" Height="1000" Width="1094"
            ResizeMode="NoResize" WindowStyle="None"
            WindowStartupLocation="CenterScreen">
        <Window.Resources>
            <DataTemplate x:Name="InvoicesViewTemplete" DataType="{x:Type viewmodels:Invoices}">
                <views:Invoices DataContext="{Binding}"/>
            </DataTemplate>
        </Window.Resources>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="300"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
                <RowDefinition Height="1*"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Vertical" Grid.Row="0" Grid.Column="0" Grid.RowSpan="5"
                <Button x:Name="InvoiceView" Content="Invoices"
                        FontSize="36" FontWeight="Heavy"
                        Height="70" Margin="5 20 5 20"
                        Click="InvoiceView_Click"/>
            </StackPanel>
            <ContentControl Grid.Row="0" Grid.RowSpan="5"
                            Grid.Column="1" Content="{Binding}"/>
            </Grid>
    </Windiw>


    • Изменено ALY_Q8 23 августа 2019 г. 10:22
    23 августа 2019 г. 10:19

Ответы

  • Never mind and Thanks 

    i found out that a ScrollViewer works like a charm on the UserControl when placed around the ContentControl in the MainWindow 

    Here is what i Added in MainWindow XAML

            <ScrollViewer x:Name="scrollViewer1"  Grid.Row="0" Grid.RowSpan="5" Grid.Column="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Hidden">
            <ContentControl Content="{Binding}"/>
            </ScrollViewer>

    and MainWindow.xaml.cs

    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void InvoiceView_Click(object sender, RoutedEventArgs e)
            {
                DataContext = new ViewModels.Invoices();
            }
    
    private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                scrollViewer1.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
                scrollViewer1.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
    
            }
        }

    Annnddd it Worked :) 
    • Помечено в качестве ответа ALY_Q8 23 августа 2019 г. 12:37
    23 августа 2019 г. 12:37

Все ответы

  • Hi,
    on Screen you can use LayoutTransform with ScaleTransform to show the whole UserControl and for printing you use the UserControl without LayouTransform.

    --
    Best Regards / Viele Grüße
    Peter Fleischer (former MVP for Developer Technologies)
    Homepage, Tipps, Tricks

    23 августа 2019 г. 11:51
  • Never mind and Thanks 

    i found out that a ScrollViewer works like a charm on the UserControl when placed around the ContentControl in the MainWindow 

    Here is what i Added in MainWindow XAML

            <ScrollViewer x:Name="scrollViewer1"  Grid.Row="0" Grid.RowSpan="5" Grid.Column="1" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Hidden">
            <ContentControl Content="{Binding}"/>
            </ScrollViewer>

    and MainWindow.xaml.cs

    public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void InvoiceView_Click(object sender, RoutedEventArgs e)
            {
                DataContext = new ViewModels.Invoices();
            }
    
    private void Window_Loaded(object sender, RoutedEventArgs e)
            {
                scrollViewer1.VerticalScrollBarVisibility = ScrollBarVisibility.Hidden;
                scrollViewer1.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden;
    
            }
        }

    Annnddd it Worked :) 
    • Помечено в качестве ответа ALY_Q8 23 августа 2019 г. 12:37
    23 августа 2019 г. 12:37