Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > Avalon

Vista - any current (November CTP) documentation building a custom controlin WPF? Help!

 
 
Old 01-10-2006   #1 (permalink)
Jason Dolinger


 
 

any current (November CTP) documentation building a custom controlin WPF? Help!

Hi all,

Does anyone have experience building their own custom controls in WPF
with the November CTP? I'm trying to develop a databound grid based on
the demo that had been available with a previous version of the WinFX
SDK. My datagrid contains 3 child grids, one for the column headers,
one for the rows headers, and one for the content itself. An object
representing each cell in the content grid extends from ContentControl.

I originally had difficulties with the dependency property system, but
I've figured out how to properly register callbacks so that changes the
bound datasource force the grid to be repopulated from the datasource.
I've got a simple XAML app which just creates a window which declares
the datasource and the grid:

<?Mapping XmlNamespace="local" ClrNamespace="Lab49.Controls" ?>
<Window x:Class="Lab49.Controls.Window1"
xmlns="http://schemas.microsoft.com/winfx/avalon/2005"
xmlns:x="http://schemas.microsoft.com/winfx/xaml/2005"
Title="DataGrid_Control"
xmlns:cc="local"
>

<Window.Resources>
<cc:MyDataView x:Key="myDataView" />
</Window.Resources>

<Grid>
<ccataGrid x:Name="myDataGrid" DataView="{StaticResource
myDataView}" Width="500" Height="500" Margin="10" />
</Grid>
</Window>

When I run the example, I only get a blank window! Nothing actually
renders ever. There must be some additional hooks into the WPF
framework that I need to use get the control to render. Could it have
to do with the style templates? I've done some reading around the fact
that you need to have a file called Themes/Generic.xaml to provide style
template data for the control. If this didn't exist, would you simply
not see your control at all? Nevertheless, I snagged the MSDN Datagrid
Generic.xaml and tried to use it with my example.

On running this time, I still get nothing. However, the Chris Sells
O'Reilly book discusses custom control implementation and states that
you must notify the control of which style template to use by including
this in your control's static constructor:

DefaultStyleKeyProperty.OverrideMetadata(typeof(DataGrid), new
FrameworkPropertyMetadata(typeof(DataGrid)));

This results in the runtime exception printed at the bottom. Does
anyone have some experience that can help in these matters?

Regards,
Jason


System.Windows.Serialization.BamlParseException was unhandled
Message="Error at element 'Grid' in markup file 'Window1.xaml' :
Exception has been thrown by the target of an invocation.."
Source="PresentationFramework"
LineNumber=0
LinePosition=0
StackTrace:
at
System.Windows.Serialization.BamlRecordReader.ReadRecord(BamlRecord
bamlRecord)
at System.Windows.Serialization.BamlRecordReader.Read(Boolean
singleRecord)
at
System.Windows.Serialization.TreeBuilderBamlTranslator.ParseFragment()
at System.Windows.Serialization.TreeBuilder.Parse()
at System.Windows.Serialization.XamlReader.LoadBaml(Stream
stream, ParserContext parserContext, Object parent, Boolean closeStream)
at
MS.Internal.AppModel.AppModelKnownContentFactory.BamlConverter(Stream
stream, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean
sandboxExternalContent)
at
MS.Internal.AppModel.MimeObjectFactory.GetObjectAndCloseStream(Stream s,
String contentType, Uri baseUri, Boolean canUseTopLevelBrowser, Boolean
sandboxExternalContent)
at
System.Windows.Navigation.NavigationService.GetObjectFromResponse(WebRequest
request, WebResponse response, Uri destinationUri, Object navState)
at System.Windows.Navigation.NavigationService.DoNavigate(Uri
source, NavigationMode f, Object navState)
at System.Windows.Navigation.NavigateQueueItem.Dispatch(Object obj)
at
System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate
callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object
source, Delegate callback, Object args, Boolean isSingleParameter,
Delegate catchHandler)
at System.Windows.Threading.DispatcherOperation.InvokeImpl()
at
System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object
state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at
System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode
code, CleanupCode backoutCode, Object userData)
at
System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Windows.Threading.DispatcherOperation.Invoke()
at System.Windows.Threading.Dispatcher.ProcessQueue()
at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd,
Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr
wParam, IntPtr lParam, Boolean& handled)
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
at
System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate
callback, Object args, Boolean isSingleParameter)
at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object
source, Delegate callback, Object args, Boolean isSingleParameter,
Delegate catchHandler)
at
System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority
priority, TimeSpan timeout, Delegate method, Object args, Boolean
isSingleParameter)
at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority
priority, Delegate method, Object arg)
at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg,
IntPtr wParam, IntPtr lParam)
at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
at
System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame
frame)
at System.Windows.Threading.Dispatcher.Run()
at System.Windows.Application.RunInternal(Window window,
String[] args)
at System.Windows.Application.Run(Window window, String[] args)
at System.Windows.Application.Run(String[] args)
at Lab49.Controls.MyApp.Main(String[] args) in C:\Documents and
Settings\jdolinger\My Documents\Visual
Studio\Projects\WPF\Lab49DataGrid\DataGrid
Control\obj\Debug\MyApp.g.cs:line 51
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

My System SpecsSystem Spec
 

Thread Tools


Similar Threads
Thread Forum
Accessing custom types output from custom cmdlet's in C# GUI PowerShell
types.custom.ps1xml for custom members PowerShell
how do I keep powershells current directory and dotnets current directory in sync PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46