开发者

Possible to use XmlDataProvider with d:DataContext?

I'm wondering how I can use an XmlDataProvider to provide arbitrary XML data for design time use in Blend 4. I've tried开发者_高级运维 a few ways of specifying it but Blend doesn't pick it up. My UI elements end up blank.

I realize Blend has functionality to generate and manage sample data but that's a lot of overhead for some of the simple user controls I have. I'm looking for something that works inline in the Xaml file (i.e. implicit schema) without a lot of extra files getting generated. Putting an XmlDataProvider in the resources and then doing a d:DataContext to reference it seemed like a good way to go but I can't make it work.

I can't use any of my viewmodel classes for this (like with a d:DesignData or using ObjectDataProvider) because they don't expose setters for all properties. Can't set those properties with design-time data if they're read-only.

How can I build a model in pure Xaml that I can bind to at design time?


If I understood you correctly,

I usually do thing in this way, yet, I can't get how complex your model is, but this a way that might be working for you in design time in order to test a specific datatemplate or such.

<Window.Resources>
        <XmlDataProvider x:Key="People" XPath="/IDs" >
            <x:XData>
                <IDs>
                    <ID name="A2231" />
                    <ID name="A3dsa" />
                    <ID name="Ad21d" />
                    <ID name="Ad231" />
                </IDs>
            </x:XData>

        </XmlDataProvider>
</Window.Resources>



  <StackPanel Grid.Row="0" Grid.Column="1" DataContext="{StaticResource People}">
            <Label Width="200" Height="200" Content="{Binding XPath=ID/@name}"/>
  </StackPanel>

Is that what you meant ? If not, please elaborate more.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜