c# - Frame doesn't work anymore after adding template -
i'm trying learn wpf
, created resource dictionary template frame
after adding template frame
doesn't display pages
anymore. when remove template, works again (the pages displayed). doing wrong?
resourcedictionary.xaml (just basic)
<resourcedictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <controltemplate x:key="frametemplate" targettype="{x:type frame}"> <grid> <border borderbrush="tomato" borderthickness="3" background="bisque"/> </grid> </controltemplate> </resourcedictionary>
mainwindow.xaml
<window.resources> <resourcedictionary> <resourcedictionary.mergeddictionaries> <resourcedictionary source="/resources/icons.xaml" /> <resourcedictionary source="resourcedictionary.xaml"/> </resourcedictionary.mergeddictionaries> </resourcedictionary> </window.resources> <controls:metrowindow.rightwindowcommands> <controls:windowcommands> <togglebutton content="menu" ischecked="{binding elementname=flyout, path=isopen}" cursor="hand"/> </controls:windowcommands> </controls:metrowindow.rightwindowcommands> <grid> <grid x:name="menu_grid"> </grid> <!-- flyout here, title bar not overlapped --> <controls:flyout x:name="flyout" width="200" header="menu" isopen="true" position="left"> <stackpanel> <button horizontalcontentalignment="center" verticalalignment="center" margin="10" click="driverbutton_click"> <stackpanel orientation="horizontal"> <rectangle height="16" width="16" margin="5"> <rectangle.fill> <visualbrush visual="{staticresource appbar_people}" stretch="fill" /> </rectangle.fill> </rectangle> <textblock verticalalignment="center" horizontalalignment="center">drivers</textblock> </stackpanel> </button> <button horizontalcontentalignment="center" verticalalignment="center" margin="10" click="seasonbutton_click"> <stackpanel orientation="horizontal"> <rectangle height="16" width="16" margin="5"> <rectangle.fill> <visualbrush visual="{staticresource appbar_calendar}" stretch="fill" /> </rectangle.fill> </rectangle> <textblock verticalalignment="center" horizontalalignment="center">seasons</textblock> </stackpanel> </button> <button horizontalcontentalignment="center" verticalalignment="center" margin="10" click="constructorsbutton_click"> <stackpanel orientation="horizontal"> <rectangle height="16" width="16" margin="5"> <rectangle.fill> <visualbrush visual="{staticresource appbar_team}" stretch="fill" /> </rectangle.fill> </rectangle> <textblock verticalalignment="center" horizontalalignment="center">constructors</textblock> </stackpanel> </button> </stackpanel> </controls:flyout> <grid margin="200 0 0 0"> <frame x:name="_mainframe" template="{staticresource frametemplate}" /> </grid> </grid>
mainwindow.xaml.cs
public partial class mainwindow { driverspage driverspage = new driverspage(); seasonpage seasonspage = new seasonpage(); constructorspage constructorspage = new constructorspage(); public mainwindow() { initializecomponent(); } private void driverbutton_click(object sender, routedeventargs e) { _mainframe.navigate(driverspage); } private void seasonbutton_click(object sender, routedeventargs e) { _mainframe.navigate(seasonspage); } private void constructorsbutton_click(object sender, routedeventargs e) { _mainframe.navigate(constructorspage); } }
when override controltemplate
, need supply entire template control. supplying grid
border
in it, going render. if @ example template frame
, see there lot more there. suspect important piece need display page content presenter named "part_framecp"
. try adding template.
<contentpresenter x:name="part_framecp" />
named parts important in templates because control them. sometimes, unnamed parts searched type , therefore may important well. idea read , understand example template when creating template of own.
Comments
Post a Comment