Creating the user control works, i can include it in the visual tree at
runtime and the control displays itself. Well the next thing you want to do
is declaring the control in a Xaml file, with the right namespace declaration.
That does'nt work.
Here is a code fragment of the register method, build according to the MSDN
page http://msdn.microsoft.com/en-us/library/ee504009.aspx:
static HRESULT Register(HINSTANCE hInstance)
{
HRESULT hr = S_OK;
hr = XRCustomUserControlImpl::Register(__uuidof(MainPageCtrl),
L"MainPageCtrl", L"clr-namespace:TC");
if (FAILED(hr))
{
return hr;
}
}
And used Xaml file:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tc="clr-namespace:TC;assembly=CE.AtlTestApp"
Width="640" Height="480">
<Grid>
<TextBox Text="hallo"></TextBox>
<StackPanel Name="Content" Background="White">
</StackPanel>
</Grid>
</UserControl>
At runtime i can add my custom control, but not at design time via the Xaml
like this.
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:tc="clr-namespace:TC;assembly=CE.AtlTestApp"
Width="640" Height="480">
<Grid>
<TextBox Text="hallo"></TextBox>
<StackPanel Name="Content" Background="White">
<tc:MainPageCtrl></tc:MainPageCtrl>
</StackPanel>
</Grid>
</UserControl>
I think we need some dependency property for this.
For other reasons i need to create an attached property, but if i follow the
MSDN it just wont work.
Here is what I tried:
static HRESULT Register(HINSTANCE hInstance)
{
HRESULT hr = S_OK;
// Get global application object
IXRApplicationPtr pApplication;
GetXRApplicationInstance(&pApplication);
// Construct default value
XRValue bstrXRValue;
bstrXRValue.SetNull();
bstrXRValue.vType = VTYPE_BSTR;
bstrXRValue.bstrStringVal = TEXT("Not set");
// Construct XRDependencyPropertyMetaData
XRDependencyPropertyMetaData dpm;
dpm.Size = sizeof(XRDependencyPropertyMetaData);
dpm.pfnPropertyChangeNotification = NULL;
dpm.pfnTypeConverter = NULL;
dpm.DefaultValue = bstrXRValue;
UINT ctrlId = 0;
const WCHAR* pPropertyName = TEXT("APXaml");
VALUE_TYPE vt;
vt = VTYPE_READONLY_STRING;
hr = pApplication->RegisterControl(__uuidof(MainPageCtrl),
L"MainPageCtrl", L"clr-namespace:TCX", &CreateMainPage, &ctrlId);
hr = pApplication->RegisterAttachedProperty( pPropertyName, vt,
ctrlId, &dpm);
return hr;
}
The control registers at runtime, but when i create it it uses a custom
callback:
// Callback function
HRESULT CreateMainPage(__in IXRDependencyObject* pExistingDependencyObject,
__out IXRDependencyObject **ppNewDp)
{
HRESULT hr = S_OK;
// Get global application object
IXRApplicationPtr pApplication;
GetXRApplicationInstance(&pApplication);
XRXamlSource Source;
Source.SetFile(TEXT("\\Storage Card\\MainPage.xaml"));
hr = pApplication->ParseXamlWithExistingRoot(&Source,
pExistingDependencyObject);
if (FAILED(hr))
return hr;
*ppNewDp = pExistingDependencyObject;
pExistingDependencyObject->AddRef();
return hr;
}
And this creates an error in xamlruntime.h
Hope someone can fill me in on how to do this.
Basically the question is how to implement dependency and attached properties?
Thanx in advance.
Gertjan Smit