我上周制定的大小会启动了“广” MainWaindow(大于1400个像素)新WPF应用程序B主窗口与先前开发的应用程序A主窗口
我在目前的时间启动一个应用程序A
开发一个新的应用程序B(它寻找运行Excel实例)
所以我有一个视图,其中包含一个DataGrid,其Width
属性Auto
(设计器图片如下)。一切都很好
然后我把它插入到主窗口(这里设计图片)
这是不是正是我的预期,但我还是不得不在SO一些研究这样的问题wpf-datagrid-why-the-extra-column(答案告诉它不是一个额外的列它是一个补充宽度...)
然后我运行这个应用程序B
。奇迹:我得到了更广阔的窗户。
确切的问题,我想在这里揭露的是:
- 为什么我会在应用
B
相同的宽度为上周的申请A
的一个运行时?
我不相信巧合(我也没有复制/粘贴2个应用程序之间)。它在哪里支持? 我已阅读关于样式的文章(默认样式,专用于不适用于继承MainWindow的窗口样式...)
阅读关于WPF的任何(实际)基本原理也值得欢迎!
编辑:添加代码(我第一次没有想显示的代码专注于问题,因为有“千”的地方,你可以设置一个宽度...生效与否。)
<UserControl ...
d:DataContext="{d:DesignInstance {x:Type vm_nmspc:MainWindowVm}, IsDesignTimeCreatable=True}">
<UserControl.Resources>
<Style TargetType="DataGridRow">
<Setter Property="Width" Value="Auto"/>
...
</Style>
</UserControl.Resources>
<Grid>
<DataGrid ItemsSource="{Binding OpenExcelColl}" AutoGenerateColumns="False" AlternationCount="{Binding OpenExcelColl.Count}"
VirtualizingPanel.IsVirtualizing="False" CanUserAddRows="False" SelectedItem="{Binding SelectedExcelObject}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True"/>
<DataGridTextColumn Header="Path" Binding="{Binding CompletePath}" IsReadOnly="True"/>
<DataGridTextColumn Header="Type" Binding="{Binding ExtType}" IsReadOnly="True"/>
</DataGrid.Columns>
...
</DataGrid>
</Grid>
</UserControl>
而且MainWindow.xaml(注意,没有宽度已获得,希望主窗口会自动适应。Width="Auto"
没有工作)
<Window ...
DataContext="{DynamicResource ResourceKey=MyVM}"
mc:Ignorable="d"
Title="MainWindow" Height="350"
SizeToContent="Width"> <<------- Line added to "workaround/solve" the problem
<Window.Resources>
<vm_nmspc:MainWindowVm x:Key="MyVM"/>
</Window.Resources>
<Grid>
<views:AllExcelObjDataGrid DataContext="{Binding}"/>
</Grid>
</Window>
后SizeToContent =“宽度”
我想我找到了答案的开始[为什么是我的wpf窗口大小默认将是巨大](http://stackoverflow.com/questions/3146106/),至少通过将* SizeToContent =“Width”*添加到Window属性。 – NGI
发布一些Xaml代码,可能发生这种情况是因为您将宽度设置为auto,因此它将占用从其父级获得的任何空间。在你的Datagrid中设置'ColumnWidth =“*”'来平分你的列之间的剩余空间。 – SilentStorm
你的问题到底是什么?预期的结果是什么? – mm8