如何在宽舒展了WPF用户控件其窗口? [英] How to stretch in width a WPF user control to its window?
问题描述
我有一个窗口,我的用户控制,我想使用户控件的宽度等于窗口宽度。 ?那怎么办
用户控件是一个水平的菜单,包含三列的网格:
< ColumnDefinition NAME =LeftSideMenuWIDTH =433/>
< ColumnDefinition名称=中WIDTH =*/>
< ColumnDefinition NAME =RightSideMenuWIDTH =90/>
这是我想要的理由窗口宽度,舒展用户控制宽度为100%,与。第二列相对
编辑:
我使用的是网格,有一个窗口的代码:
<窗口x:类=TCI.Indexer.UI.Operacao
的xmlns =HTTP:/ /schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
的xmlns:TCI =CLR - 命名空间:TCI.Indexer.UI.Controles
标题=了minHeight =550了minWidth =675加载=装载ResizeMode =NoResizeWindowStyle =无WindowStartupLocation =中心屏幕的WindowState =最大化调焦=真
X:NAME =windowOperacao>
<帆布X:NAME =canv>
<网格和GT;
< TCI:状态X:NAME =ucStatus/> <! - 我想在宽度延长控制 - >
< /网格和GT;
< /帆布>
< /窗GT;
您需要确保你的用户控件尚未确定这是在该用户的XAML文件宽度。只是删除了宽度=...,从它,你是好去。
编辑:这是我测试代码它:
的 SOUserAnswerTest.xaml:的
<用户控件X:类=WpfApplication1.SOAnswerTest
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =HTTP ://schemas.microsoft.com/winfx/2006/xaml
HEIGHT =300>
<网格和GT;
< Grid.ColumnDefinitions>
< ColumnDefinition NAME =LeftSideMenuWIDTH =100/>
< ColumnDefinition名称=中WIDTH =*/>
< ColumnDefinition NAME =RightSideMenuWIDTH =90/>
< /Grid.ColumnDefinitions>
将; TextBlock的Grid.Column =0>一种与所述; / TextBlock的>
< TextBlock的Grid.Column =1> B< / TextBlock的>
< TextBlock的Grid.Column =2> C< / TextBlock的>
< /网格和GT;
< /用户控件>
的 Window1.xaml:的
<窗口x:类=WpfApplication1.Window1
的xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
的xmlns:地方=CLR的命名空间:WpfApplication1
标题=窗口1 HEIGHT =300WIDTH =415>
<网格和GT;
<局部:SOAnswerTest Grid.Column =0Grid.Row =5Grid.ColumnSpan =2/>
< /网格和GT;
< /窗GT;
I have a Window with my user control and I would like to make usercontrol width equals window width. How to do that?
The user control is a horizontal menu and contains a grid with three columns:
<ColumnDefinition Name="LeftSideMenu" Width="433"/>
<ColumnDefinition Name="Middle" Width="*"/>
<ColumnDefinition Name="RightSideMenu" Width="90"/>
That is the reason I want the window width, to stretch the user control to 100% width, with the second column relative.
EDIT:
I am using a grid, there is the code for Window:
<Window x:Class="TCI.Indexer.UI.Operacao"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tci="clr-namespace:TCI.Indexer.UI.Controles"
Title=" " MinHeight="550" MinWidth="675" Loaded="Load" ResizeMode="NoResize" WindowStyle="None" WindowStartupLocation="CenterScreen" WindowState="Maximized" Focusable="True"
x:Name="windowOperacao">
<Canvas x:Name="canv">
<Grid>
<tci:Status x:Name="ucStatus"/> <!-- the control which I want to stretch in width -->
</Grid>
</Canvas>
</Window>
You need to make sure your usercontrol hasn't set it's width in the usercontrol's xaml file. Just delete the Width="..." from it and you're good to go!
EDIT: This is the code I tested it with:
SOUserAnswerTest.xaml:
<UserControl x:Class="WpfApplication1.SOAnswerTest"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Name="LeftSideMenu" Width="100"/>
<ColumnDefinition Name="Middle" Width="*"/>
<ColumnDefinition Name="RightSideMenu" Width="90"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0">a</TextBlock>
<TextBlock Grid.Column="1">b</TextBlock>
<TextBlock Grid.Column="2">c</TextBlock>
</Grid>
</UserControl>
Window1.xaml:
<Window x:Class="WpfApplication1.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="Window1" Height="300" Width="415">
<Grid>
<local:SOAnswerTest Grid.Column="0" Grid.Row="5" Grid.ColumnSpan="2"/>
</Grid>
</Window>
这篇关于如何在宽舒展了WPF用户控件其窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!