根據用戶控件的大小調整面板的大小 (Resizing a Panels based on the size of user control)


問題描述

根據用戶控件的大小調整面板的大小 (Resizing a Panels based on the size of user control)

I'm trying to find a way to resize a LayoutPanel (DevExpress) based on the size of the user control that it contains. The user control is exposed using a ContentControl. Here's the relevant Code This is the Layout panel and the coresponding view:

<dxd:LayoutPanel Caption="Search Criteria" CaptionImage="Images/Icons/DetailView.png">
   <ContentControl Name="myContentControl" Content="{Binding Path=ProjectsSearchVM}"/>
 </dxd:LayoutPanel>

The ProjectSearchVM is a property of the MainWindowViewModel, which is the DataContext for the code above. This property returns an object of type ProjectsSearchViewModel that is replaced by its corresponding View (containing a userControl) using a Resource File:

<DataTemplate DataType="{x:Type vm:ProjectSearchViewModel}">
  <vw:ProjectSearchView />
</DataTemplate>

The problem is that my view is higher than the original size of the Layout Pannel. I'd like to bind the panel's MinSize to the size of my view (or the ContentControl containing it). 

I tried this, but it doesn't work:

<dxd:LayoutPanel Caption="Search Criteria" CaptionImage="Images/Icons/DetailView.png">
  <dxd:LayoutPanel.MinSize>
    <Binding ElementName="myContentControl" Path="Size"/>
  </dxd:LayoutPanel.MinSize>


   <ContentControl Name="myContentControl" Content="{Binding Path=ProjectsSearchVM}" />
</dxd:LayoutPanel>

I'm still very new to WPF, so I'm sure the solution is simple. Can anyone enlighten me?


參考解法

方法 1:

The question was answered on the DevExpress site at this link:

http://www.devexpress.com/Support/Center/Question/Details/Q448884

For flyout, it involves overriding the control in the container, for example, if it's in a Border, something like this:

public class AutoSizeContainer : Border {
        protected override void OnInitialized(EventArgs e) {
            base.OnInitialized(e);
            BaseLayoutItem item = DockLayoutManager.GetLayoutItem(this);
            Child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            AutoHideGroup.SetAutoHideSize(item, new Size(Child.DesiredSize.Width + 6, Child.DesiredSize.Height + 6));
        }
    }

Making such an object the root object of the LayoutPanel in an AutoHide group, makes the flyout sizing correct. 

(by LukaszRob Perkins)

參考文件

  1. Resizing a Panels based on the size of user control (CC BY-SA 3.0/4.0)

#devexpress #wpf #binding #xaml






相關問題

修改 aspxgrid 中的列以顯示超鏈接和支持組 (Modify column in aspxgrid to display a hyper link and support group by)

沒有標誌的Javascript不區分大小寫的正則表達式 (Javascript case insensitive regex without flags)

MVC 4 - Gặp lỗi khi cố gắng thêm một báo cáo mới (MVC 4 - Getting error while trying to add a new report)

網格列包含 int64 值,但過濾器顯示字符串並且不起作用/ (Grid column contains int64 values but filter shows strings and doesn't work/)

我應該每年為保持 devexpress 應用程序的運行付費嗎 (Should I pay every year for keep devexpress app running)

Excel 和 Word DevExpress (Excel & Word DevExpress)

用於 ASP.NET Web 應用程序的 DevExpress 與 Telerik 網格 (DevExpress vs. Telerik grids for ASP.NET web applications)

添加控件會導致 Silverlight 掛起 (Adding controls causes silverlight to hang)

根據用戶控件的大小調整面板的大小 (Resizing a Panels based on the size of user control)

vs2010 asp.net設置斷點問題 (Problem in setting breakpoint in vs2010 asp.net)

單擊按鈕後行命令不觸發 (Rowcommand do not fire after clicking button)

DevExpress 11.1 在 IIS 7+ 中不起作用 (DevExpress 11.1 not functional in IIS 7+)







留言討論