User avatar
jsantos
Site Admin
Posts: 4266
Joined: 20 Jan 2012, 17:18
Contact:

Re: A few questions about some features

24 Mar 2015, 14:14

And I imagine it works fine in the XamlPlayer right?

Ok, I will try to do the same, using the UserControl tutorial code in the Integration Sample.
 
ZanAlex
Topic Author
Posts: 66
Joined: 16 Jan 2015, 17:46

Re: A few questions about some features

24 Mar 2015, 14:19

Yes it does work in the XamlPlayer.

Thank you for your help :)
 
User avatar
jsantos
Site Admin
Posts: 4266
Joined: 20 Jan 2012, 17:18
Contact:

Re: A few questions about some features

24 Mar 2015, 19:32

I have found a very strange bug that I think is the problem you are observing. Unfortunately, a new version is required to solve it. Could you please file a bug? I will provide you a hotfix for evaluation.

Thanks!
 
User avatar
sfernandez
Site Admin
Posts: 3222
Joined: 22 Dec 2011, 19:20

Re: A few questions about some features

07 Apr 2015, 21:07

My second problem is a bit more mysterious. As I said, I'm trying to spawn controls from my application code. One of my goals is to fill a StackPanel with a custom control containing a custom drop down menu. But as soon as I try to add one in the Panel (using UIElementCollection::Add), the application crashes. Here are some code snippets:

test.xaml, loaded by the application:
<Border
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  HorizontalAlignment="Center" VerticalAlignment="Center"
  x:Name="PART_BorderTest"
  UseLayoutRounding="True">
	
	<FilterBar x:Name="PART_FilterBar" />
	
</Border>
filterBar.xaml
<FilterBar
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="FilterBar" x:Name="FilterBar"
  UseLayoutRounding="True">

	<StackPanel x:Name="PART_CategoryPanel" Orientation="Horizontal" />
	
</FilterBar>
filterCategory.xaml
<FilterCategory
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="FilterCategory" x:Name="FilterCategory"
  UseLayoutRounding="True">
	
	<FilterCategory.Resources>
		<ControlTemplate x:Key="MenuAnchorTemplate" TargetType="{x:Type MenuAnchor}">
			<StackPanel Orientation="Vertical">
				<StackPanel Orientation="Horizontal">
					<ContentPresenter x:Name="PART_HeaderContent"
					  Content="{Binding HeaderContent, RelativeSource={RelativeSource TemplatedParent}}"/>
					<ToggleButton IsChecked="{Binding IsMenuOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"/>
				</StackPanel>
				<Popup x:Name="PART_Popup"
				  IsOpen="{Binding IsMenuOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
				  Focusable="False"
				  PlacementTarget="{Binding ElementName=PART_HeaderContent}"
				  Placement="Bottom"
				  PopupAnimation="Slide"
				  VerticalOffset="1"
				  AllowsTransparency="True"
				  StaysOpen="True">
					<ContentPresenter/>
				</Popup>
			</StackPanel>
		</ControlTemplate>
		<Style TargetType="{x:Type MenuAnchor}">
			<Setter Property="Template" Value="{StaticResource MenuAnchorTemplate}"/>
		</Style>
	</FilterCategory.Resources>
	
	<MenuAnchor>
		<MenuAnchor.HeaderContent>
			<StackPanel Orientation="Horizontal">
				<CheckBox/>
				<TextBlock Text="{Binding CategoryID, Mode=TwoWay, StringFormat=F2}" />
			</StackPanel>
		</MenuAnchor.HeaderContent>
		
		<StackPanel x:Name="PART_FilterPanel" Orientation="Vertical"/>
	</MenuAnchor>
	
</FilterCategory>
Note that I've encountered both problems using that ControlTemplate for MenuAnchor (the custom drop down menu) shown in filterCategory.xaml.

Add function
Noesis::Gui::UIElementCollection* pCol = _filtersCategoriesPanel->GetChildren();
if (pCol != nullptr)
{
    pCol->Add(pNewCategory);
}
I've been looking at this code and I think there is something wrong with the design.

Custom Controls don't have a xaml associated with the class, so when you reference a custom control from another xaml like in test.xaml, you cannot expect that FilterBar instance will contain a StackPanel named "PART_CategoryPanel" set as content. PART_ elements must be defined in the control template in the same way you did with the MenuAnchorTemplate.

If you need to associate a xaml with a control, then you need to create a UserControl, and override the UserControl.Source property to specify which xaml file must be loaded when your user control gets created.

I tried to add some custom controls to a panel without problem so my guess is that the crash you were getting was because the _filtersCategoriesPanel was null (maybe you were assuming that filterCategory.xaml would be loaded and PART_FilterPanel element could be found). Could that be possible?
 
ZanAlex
Topic Author
Posts: 66
Joined: 16 Jan 2015, 17:46

Re: A few questions about some features

08 Apr 2015, 09:29

Hi,

I've let that part in stand-by for a quite a while now, I'll have another look at it and let you know if I encounter problems. I've learned quite a lot about the framework since then.

Thank you!
 
User avatar
sfernandez
Site Admin
Posts: 3222
Joined: 22 Dec 2011, 19:20

Re: A few questions about some features

08 Apr 2015, 13:44

It's working great, thank you so much! :)

Actually, it works in the XamlPlayer, but as soon as I try to integrate it in my application, bad things happens.
<Border
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Name="Root"
  BorderBrush="White" BorderThickness="1"
  HorizontalAlignment="Center" VerticalAlignment="Center">
   
    <!--<Border.Resources>
        <ResourceDictionary>
            <InventoryTileModel x:Key="model" ItemID="0" Quantity="10" />
        </ResourceDictionary>
    </Border.Resources>-->

    <Image
      Source="./assets/woodicon.png"
      Height="60" Width="60" />
    
</Border>
As soon as I uncomment the Border resources, I get that error:
File Core\Kernel\Src\Memory.cpp (l. 130): Not enough memory! (malloc(15627680408))
The weird thing is that everything is working in the XamlPlayer. Do you have a lead on what might be wrong with that? Thank you.
Coming back to this issue I guess this problem was related with the serialization bug we solved in 1.2.2.

Could you also check that setting back the view model in the xaml is working as expected?

Thanks for your collaboration.

Who is online

Users browsing this forum: Google [Bot] and 3 guests