c# - How to view collapsed elements while designing a WPF control? -
i set datagrid collapse when there no items
<datagrid name="datagrid" visibility="{binding hasitems, elementname=datagrid, converter={staticresource booleantovisibilityconverter}}"> </datagrid>
the problem is, appear on design mode. how it? should create fake data?
i tried
private void usercontrol_loaded(object sender, routedeventargs e) { if (designerproperties.getisindesignmode(this)) { this.datagrid.itemssource = new list<table> { new table() }; } }
but didn't work
if understand trying do, works me:
<window x:class="wpfscratch.mainwindow" xmlns:local="clr-namespace:wpfscratch" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:ignorable="d" d:designheight="300" d:designwidth="592" d:datacontext="{d:designinstance local:mydesigntimeviewmodel, isdesigntimecreatable=true}" title="mainwindow" sizetocontent="widthandheight"> <window.resources> <local:booltovisibilityconverter x:key="booltohiddenconverter" truevalue="visible" falsevalue="hidden" /> </window.resources> <dockpanel> <datagrid name="datagrid" itemssource="{binding people}" visibility="{binding hasitems, elementname=datagrid, converter={staticresource booltohiddenconverter}}" autogeneratecolumns="true"> </datagrid> </dockpanel>
public class mydesigntimeviewmodel { public observablecollection<person> people { { return new observablecollection<person> { new person { name = "simon" }, new person { name = "jack" } }; } } } public class person { public string name { get; set; } }
Comments
Post a Comment