WPF datagrid 列宽问题 用到了dev的DockLayoutManager 急在线等!

黄大仙儿 2015-03-17 10:35:53
datagrid是放在devexpress的DockLayoutManager里的DocumentGroup里的LayoutPanel中

<DataGrid Grid.Row="2" Name="dataGrid_CalTask" Style="{StaticResource dataGridCalTask}">
<DataGrid.Columns>
<DataGridTextColumn Header="name" Width="*" Binding="{Binding name}"/>
<DataGridTextColumn Header="value" Width="2*" Binding="{Binding value}"/>
</DataGrid.Columns>
</DataGrid>

这是正常的,怎么缩放都没事


但是,把这个layoutpanel拖出来以后就有问题了

就算在sizechanged函数里重新绑定数据源,也还是这样
在又改变panel大小以后,有时还会多出最后一列空白列


求解决办法!感谢!
...全文
370 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
把 panel 换成 ViewBox就可以了
exception92 2015-03-23
  • 打赏
  • 举报
回复
引用 10 楼 huang369509940 的回复:
[quote=引用 9 楼 duanzi_peng 的回复:]
有问题么??

!!太感谢你了 你把这个计算过程监控这个窗口给拉出来 是不是就变成我图2那样了[/quote]
黄大仙儿 2015-03-23
  • 打赏
  • 举报
回复
引用 22 楼 duanzi_peng 的回复:
[quote=引用 21 楼 huang369509940 的回复:] [quote=引用 20 楼 duanzi_peng 的回复:] j解释不了。。。。。。
那像这种数据绑定DataGrid的操作到底应该是放在构造函数里还是放在Load里啊?[/quote] 我一般不这么绑定的。我不指定它的ItemsSource 。 我 指定当前window的DataContext对象,然后我通过binding形式 把数据集绑定到它的ItemsSource上的。[/quote] 哦。。我没学过WPF 自己瞎琢磨 那种感觉好复杂的 我就用省事的了 哈哈 谢谢谢谢!
exception92 2015-03-23
  • 打赏
  • 举报
回复
引用 21 楼 huang369509940 的回复:
[quote=引用 20 楼 duanzi_peng 的回复:] j解释不了。。。。。。
那像这种数据绑定DataGrid的操作到底应该是放在构造函数里还是放在Load里啊?[/quote] 我一般不这么绑定的。我不指定它的ItemsSource 。 我 指定当前window的DataContext对象,然后我通过binding形式 把数据集绑定到它的ItemsSource上的。
黄大仙儿 2015-03-23
  • 打赏
  • 举报
回复
引用 20 楼 duanzi_peng 的回复:
j解释不了。。。。。。
那像这种数据绑定DataGrid的操作到底应该是放在构造函数里还是放在Load里啊?
exception92 2015-03-23
  • 打赏
  • 举报
回复
引用 19 楼 huang369509940 的回复:
[quote=引用 18 楼 huang369509940 的回复:] [quote=引用 17 楼 duanzi_peng 的回复:] [quote=引用 16 楼 huang369509940 的回复:] [quote=引用 15 楼 duanzi_peng 的回复:] 13.1 的。 测试的 拖动自如。 应该是 某一个样式的问题吧,这跟你的数据源有么有关系。
嗯找到问题了,我少说了一个属性,FloatingMode="Desktop",我以为没有关系,你加上这个试试看 <dxdo:DockLayoutManager Name="dockLayoutManager1" FloatingMode="Desktop">[/quote] 我这原本都有,,[/quote] WTF,难道是dev版本的问题??我加上FloatingMode="Desktop"以后就这样。。。 你这个是弄的Frame的吗?

                    <dxdo:LayoutPanel Caption="计算过程监控" Name="lp_calculate">
                        <Grid>
                            <Frame Name="CalculateFrame" Source="CalInfoPage.xaml" NavigationUIVisibility="Hidden"/>
                        </Grid>
                    </dxdo:LayoutPanel>
DataGrid在CalInfoPage.xaml里,Page_Loaded事件里进行数据绑定[/quote] 我靠我知道了,我把数据绑定放在Page的构造函数里就不会出现这个问题了,放在Page_Loaded里就会这样。 这是为啥。。。难道这种操作不是应该放在Load里才对嘛??[/quote] j解释不了。。。。。。
黄大仙儿 2015-03-23
  • 打赏
  • 举报
回复
引用 18 楼 huang369509940 的回复:
[quote=引用 17 楼 duanzi_peng 的回复:] [quote=引用 16 楼 huang369509940 的回复:] [quote=引用 15 楼 duanzi_peng 的回复:] 13.1 的。 测试的 拖动自如。 应该是 某一个样式的问题吧,这跟你的数据源有么有关系。
嗯找到问题了,我少说了一个属性,FloatingMode="Desktop",我以为没有关系,你加上这个试试看 <dxdo:DockLayoutManager Name="dockLayoutManager1" FloatingMode="Desktop">[/quote] 我这原本都有,,[/quote] WTF,难道是dev版本的问题??我加上FloatingMode="Desktop"以后就这样。。。 你这个是弄的Frame的吗?

                    <dxdo:LayoutPanel Caption="计算过程监控" Name="lp_calculate">
                        <Grid>
                            <Frame Name="CalculateFrame" Source="CalInfoPage.xaml" NavigationUIVisibility="Hidden"/>
                        </Grid>
                    </dxdo:LayoutPanel>
DataGrid在CalInfoPage.xaml里,Page_Loaded事件里进行数据绑定[/quote] 我靠我知道了,我把数据绑定放在Page的构造函数里就不会出现这个问题了,放在Page_Loaded里就会这样。 这是为啥。。。难道这种操作不是应该放在Load里才对嘛??
黄大仙儿 2015-03-23
  • 打赏
  • 举报
回复
引用 17 楼 duanzi_peng 的回复:
[quote=引用 16 楼 huang369509940 的回复:] [quote=引用 15 楼 duanzi_peng 的回复:] 13.1 的。 测试的 拖动自如。 应该是 某一个样式的问题吧,这跟你的数据源有么有关系。
嗯找到问题了,我少说了一个属性,FloatingMode="Desktop",我以为没有关系,你加上这个试试看 <dxdo:DockLayoutManager Name="dockLayoutManager1" FloatingMode="Desktop">[/quote] 我这原本都有,,[/quote] WTF,难道是dev版本的问题??我加上FloatingMode="Desktop"以后就这样。。。 你这个是弄的Frame的吗?

                    <dxdo:LayoutPanel Caption="计算过程监控" Name="lp_calculate">
                        <Grid>
                            <Frame Name="CalculateFrame" Source="CalInfoPage.xaml" NavigationUIVisibility="Hidden"/>
                        </Grid>
                    </dxdo:LayoutPanel>
DataGrid在CalInfoPage.xaml里,Page_Loaded事件里进行数据绑定
exception92 2015-03-23
  • 打赏
  • 举报
回复
引用 16 楼 huang369509940 的回复:
[quote=引用 15 楼 duanzi_peng 的回复:] 13.1 的。 测试的 拖动自如。 应该是 某一个样式的问题吧,这跟你的数据源有么有关系。
嗯找到问题了,我少说了一个属性,FloatingMode="Desktop",我以为没有关系,你加上这个试试看 <dxdo:DockLayoutManager Name="dockLayoutManager1" FloatingMode="Desktop">[/quote] 我这原本都有,,
黄大仙儿 2015-03-23
  • 打赏
  • 举报
回复
引用 15 楼 duanzi_peng 的回复:
13.1 的。 测试的 拖动自如。 应该是 某一个样式的问题吧,这跟你的数据源有么有关系。
嗯找到问题了,我少说了一个属性,FloatingMode="Desktop",我以为没有关系,你加上这个试试看 <dxdo:DockLayoutManager Name="dockLayoutManager1" FloatingMode="Desktop">
exception92 2015-03-23
  • 打赏
  • 举报
回复
引用 13 楼 huang369509940 的回复:
[quote=引用 11 楼 duanzi_peng 的回复:] [quote=引用 10 楼 huang369509940 的回复:] [quote=引用 9 楼 duanzi_peng 的回复:] 有问题么??
!!太感谢你了 你把这个计算过程监控这个窗口给拉出来 是不是就变成我图2那样了[/quote] [/quote] 尼玛 为什么我的列宽就变了啊 我是这么绑定数据的

            DataTable dt = new DataTable();
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("value", typeof(string));
            for (int i = 0; i < filelist.Length; i++)
            {
                string line = filelist[i];
                string name = line.Split('\t')[0];
                string value = line.Split('\t')[1];
                dt.Rows.Add(name, value);
            }
            dataGrid_CalTask.ItemsSource = dt.DefaultView;
你dev的版本是多少啊?[/quote] 13.1 的。 测试的 拖动自如。 应该是 某一个样式的问题吧,这跟你的数据源有么有关系。
黄大仙儿 2015-03-23
  • 打赏
  • 举报
回复
引用 12 楼 piaopiao_lucky 的回复:
把 panel 换成 ViewBox就可以了
确切的说我都没用到panel啊。。
黄大仙儿 2015-03-23
  • 打赏
  • 举报
回复
引用 11 楼 duanzi_peng 的回复:
[quote=引用 10 楼 huang369509940 的回复:] [quote=引用 9 楼 duanzi_peng 的回复:] 有问题么??
!!太感谢你了 你把这个计算过程监控这个窗口给拉出来 是不是就变成我图2那样了[/quote] [/quote] 尼玛 为什么我的列宽就变了啊 我是这么绑定数据的

            DataTable dt = new DataTable();
            dt.Columns.Add("name", typeof(string));
            dt.Columns.Add("value", typeof(string));
            for (int i = 0; i < filelist.Length; i++)
            {
                string line = filelist[i];
                string name = line.Split('\t')[0];
                string value = line.Split('\t')[1];
                dt.Rows.Add(name, value);
            }
            dataGrid_CalTask.ItemsSource = dt.DefaultView;
你dev的版本是多少啊?
exception92 2015-03-20
  • 打赏
  • 举报
回复
有问题么??
黄大仙儿 2015-03-20
  • 打赏
  • 举报
回复
引用 9 楼 duanzi_peng 的回复:
有问题么??
!!太感谢你了 你把这个计算过程监控这个窗口给拉出来 是不是就变成我图2那样了
黄大仙儿 2015-03-19
  • 打赏
  • 举报
回复
有没有大神来帮帮忙啊
黄大仙儿 2015-03-18
  • 打赏
  • 举报
回复
引用 1 楼 duanzi_peng 的回复:
把你的dataGridCalTask 贴出来看看

    <!--dataGrid的基本样式-->
    <Style x:Key="dataGridBaseStyle"  TargetType="{x:Type DataGrid}">
        <Setter Property="AutoGenerateColumns" Value="False"></Setter>
        <Setter Property="IsReadOnly" Value="True"></Setter>
        <Setter Property="CanUserSortColumns" Value="False"></Setter>
        <Setter Property="CanUserReorderColumns" Value="False"></Setter>
    </Style>
    <!--列表的dataGrid中所有的样式-->
    <!--datagrid单元格内容居中-->
    <Style x:Key="gridCellCenter" TargetType="DataGridCell">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DataGridCell">
                    <TextBlock TextAlignment="Center" VerticalAlignment="Center"  >
                           <ContentPresenter />
                    </TextBlock>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!--datagrid行列头的样式-->
    <Style x:Key="gridRowHeader" TargetType="DataGridRowHeader">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Height" Value="26"/>
    </Style>
    <!--dataGrid的样式-->
    <Style x:Key="dataGridStyle" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource dataGridBaseStyle}">
        <Setter Property="CellStyle" Value="{StaticResource gridCellCenter}"></Setter>
        <Setter Property="ColumnHeaderStyle" Value="{StaticResource gridColumnHeader}"></Setter>
        <Setter Property="RowHeaderStyle" Value="{StaticResource gridRowHeader}"></Setter>
        <Setter Property="FontSize" Value="15"/>
        <Setter Property="Margin" Value="20"></Setter>
        <Setter Property="Background" Value="{x:Null}"></Setter>
        <Setter Property="Foreground" Value="White"></Setter>
        <Setter Property="BorderBrush" Value="Black"></Setter>
        <Setter Property="AlternatingRowBackground" Value="#8C81C5CE"></Setter>
        <Setter Property="RowBackground" Value="#8C2D77B7"></Setter>
    </Style>

    <!--任务表的dataGrid的样式-->
    <Style x:Key="dataGridCalTask"  TargetType="{x:Type DataGrid}" BasedOn="{StaticResource dataGridStyle}">
        <Setter Property="FontSize" Value="20"/>
        <Setter Property="BorderBrush" Value="{x:Null}"></Setter>
        <Setter Property="ColumnHeaderStyle">
            <Setter.Value>
                <Style TargetType="DataGridColumnHeader">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Setter Property="Height" Value="0"/>
                </Style>
            </Setter.Value>
        </Setter>
    </Style>
exception92 2015-03-18
  • 打赏
  • 举报
回复
把你的dataGridCalTask 贴出来看看
黄大仙儿 2015-03-18
  • 打赏
  • 举报
回复
引用 6 楼 duanzi_peng 的回复:
[quote=引用 5 楼 duanzi_peng 的回复:] [quote=引用 4 楼 huang369509940 的回复:] [quote=引用 3 楼 duanzi_peng 的回复:] 看着没问题呀。 缩放怎么不使用ViewBox?
额 不太了解ViewBox 对文字大小没要求呀 你要不写个小程序试验一下。。复现一下这个问题[/quote] 你把 panel 换成 ViewBox 测试测试呗[/quote] 只要 限定了 datagrid的宽高 使用ViewBox 是可以实现缩放的。[/quote] 呃 我之前说的panel是简说了 实际用的是dev的layoutpanel

        <dxdo:DockLayoutManager Grid.Row="1" x:Name="dockLayoutManager" Background="{x:Null}" FloatingMode="Desktop" DockItemClosed="dockLayoutManager_DockItemClosed" EnableWin32Compatibility="True">
            <dxdo:LayoutGroup Orientation="Horizontal">
                <dxdo:LayoutGroup x:Name="MenuGroup" HorizontalAlignment="Left" ItemWidth="140" VerticalAlignment="Center">
                    <dxdo:LayoutPanel Caption="首页" ShowCloseButton="False" ShowControlBox="False" ShowMaximizeButton="False" ShowRestoreButton="False" Name="lp_menu" Visibility="Collapsed">
                        <Grid Width="140" VerticalAlignment="Center" Background="{StaticResource ParentBG}">
                        </Grid>
                    </dxdo:LayoutPanel>
                </dxdo:LayoutGroup>
                <dxdo:DocumentGroup x:Name="documentContainer" DestroyOnClosingChildren="False" ShowDropDownButton="False" FontSize="15" SelectedItemChanged="documentContainer_SelectedItemChanged">
                    <dxdo:DocumentGroup.Background>
                        <ImageBrush/>
                    </dxdo:DocumentGroup.Background>
                    <dxdo:LayoutPanel Caption="首页" Name="lp_index" ShowCloseButton="False" AllowClose="False" AllowFloat="False" AllowDrag="False">
                        <Grid>
                        </Grid>
                    </dxdo:LayoutPanel>
                    <dxdo:LayoutPanel Caption="计算过程监控" Name="lp_calculate" Visibility="Collapsed">
                        <Grid>
                            <Frame Name="CalculateFrame" Source="CalInfoPage.xaml" NavigationUIVisibility="Hidden"/>
                        </Grid>
                    </dxdo:LayoutPanel>
                </dxdo:DocumentGroup>
            </dxdo:LayoutGroup>
        </dxdo:DockLayoutManager>
这个datagrid是在CalInfoPage.xaml这个page里
exception92 2015-03-18
  • 打赏
  • 举报
回复
引用 5 楼 duanzi_peng 的回复:
[quote=引用 4 楼 huang369509940 的回复:] [quote=引用 3 楼 duanzi_peng 的回复:] 看着没问题呀。 缩放怎么不使用ViewBox?
额 不太了解ViewBox 对文字大小没要求呀 你要不写个小程序试验一下。。复现一下这个问题[/quote] 你把 panel 换成 ViewBox 测试测试呗[/quote] 只要 限定了 datagrid的宽高 使用ViewBox 是可以实现缩放的。
加载更多回复(3)

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧