My UserControl isn't being rendered when used

2019-09-06 08:37发布

I have a UserControl defined in MyUserControl.xaml. If I reference this directly from another control, then it displays correctly. For example:

<Grid>
    <MyUserControl/>
<Grid>

works as expected. But if I try to use the UserControl in a DataTemplate it doesn't work. For example, if I have a DataTemplate like

<DataTemplate>
   <MyUserControl/>
<DataTemplate>

nothing gets rendered.

What's up?

1条回答
姐就是有狂的资本
2楼-- · 2019-09-06 09:06

Does your UserControl have a corresponding .xaml.cs file? This seems to happen when it doesn't.

If you're using Visual Studio, try copying all the XAML from your UserControl, then deleting it from your project, adding a new UserControl (with the same name as before), then pasting your content back into the XAML file. This will ensure that you have the correct .xaml.cs file set up.

查看更多
登录 后发表回答