pixelsense - ScatterViewItem custom size -


I develop surface app using the MVVM pattern. I have different views and I want to put them in a scatterview. I want my ScatterViewItem size to fit the size of my scene?

Code example:

  DataTemplate DataType = "{x: type vm: PointListViewModel}" & gt; & Lt; Grid & gt; & Lt; V: PointListView & gt; & Lt; / V: PointListView & gt; & Lt; / Grid & gt; & Lt; / DataTemplate & gt; & Lt; DataTimeplate DataType = "{x: Type VM: Bluetooth devices ViewModel}" & gt; & Lt; Grid & gt; & Lt; V: BluetoothDevicesView & gt; & Lt; / V: BluetoothDevicesView & gt; & Lt; / Grid & gt; & Lt; / DataTemplate & gt;  

....

  & lt; S: scatterview grid Rowspan = "3" datacentext = "{binding path = workspace}" itemsource = "{binding}" item template = "{binding}" cliptoobons = "true" allow = "true" & gt; & Lt; / S: ScatterView & gt;  

... This code works fine but all of my views have the same size. I tried to configure ScatterViewItem with style:

  style based on = "{StaticResource {x: types: ScatterViewItem}}" TargetType = "{x: types s: ScatterViewItem}" & Gt; & Lt; Setter property = "height" value = "auto" /> & Lt; Setter property = "width" value = "auto" /> & Lt; / Style & gt;  

But it does not work.

Update: I have answered this in a code project article: - Check this for more details and full sample code


It is very difficult to get it right. I had this problem a while ago and tried many different ways - I changed the size automatically Implemented its own ScatterViewItem - but never found 100% work solution.

The solution I have solved, the main problem of getting the initial size was to create a custom control that it was created when its parent, ScatterViewTime Attached properties were used to set up. For this, the full code is of bigger space here, but I will try to explain the core to get you started.

So whenever I add data to my scatterview (via datbasing), the contents of My Itemtemplate ScatterViewItem will be set to control the control called "PopupWindows" (which comes with user control). PopWindow has defined an attached property called InitialSizeRequest (type) that appears in its child element in its loaded event handler, in this view tree upwards ScatterViewItem searches to find and its size is set accordingly.

The generated visual tree will look like this:

  scatterview "- scattervuiteum - popupwando '- actual content (dataappplate)  

On the actual content, they will declare their size as follows:

  & lt; UserControl x: Class = "...." ... Local View: Popup Window Initial syisest = "450,400" />  

To capture the actual content from popup windows, I used the code given below (error investigation). This popup is executed in the Window's Loaded event:

  // GUIHelpers is a support group that I have created to find the elements in the visual tree / c_contentHolder ContentControl that will present the actual content of the var presenter = GuiHelpers.GetChildObject & lt; ContentPresenter & gt; (C_contentHolder); // It seems that ContentPresenter believes it will be always a child / child and that child will be the visual representation of the actual content. Var kids = VisualTreeHelper.GetChild (presenter, 0); Size Size = Popup Window.GetInitialSizeRequest (Toddler); // Now Parents ScatterViewItem var svi = GuiHelpers.GetParentObject & lt; ScatterViewItem & gt; Use the requested size to set the size of (this, false); Svi.Width = Requested size. With; Svi.Height = Requested size. height;  

Hope this should get you started. Please comment if you need further explanations.


Comments