热重新加载与某些标签无法正常工作? (viewcell/datatemplate)

发布于 2025-02-05 20:40:28 字数 2300 浏览 1 评论 0原文

我有此XAML,

<Label Text="Logfile" FontAttributes="Bold" Margin="0,0,0,10" />
<ListView ItemsSource="{Binding LogEntries}">
  <ListView.ItemTemplate>
    <DataTemplate  x:DataType="model:LogEntity">
      <ViewCell>
        <Grid RowDefinitions="*,*" BackgroundColor="Blue">
        
          <Label Text="{Binding Message}" Grid.Row="0"></Label>
          <Label Text="{Binding  LogTime}" Grid.Row="1"></Label>
        
        </Grid>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

如果我更改这些标签,

<Label Text="Logfile" FontAttributes="Bold" Margin="0,0,0,10" />
<ListView ItemsSource="{Binding LogEntries}">

则更改立即出现在应用程序中。但是,当我更改此标签中的任何内容时,

<ViewCell>
  <Grid RowDefinitions="*,*" BackgroundColor="Blue">
            
    <Label Text="{Binding Message}" Grid.Row="0"></Label>
    <Label Text="{Binding  LogTime}" Grid.Row="1"></Label>
            
  </Grid>
</ViewCell>

什么都不会发生。

有什么已知的限制吗?也许是因为它在DataTemplate内部?我在这里没有看到任何限制: https://learn.microsoft.com/en-us/visalstudio/xaml-tools/xaml-hot-hot-reload-troubleshooting?view = vs-2022

我正在使用Visual Visual Studio 2022版本17.3.0预览1.1。

我在Visual Studio中的设置是:

调试 - &GT; .net/c ++热重载(可能与此上下文无关)

调试 - &gt; XAML热重新加载

我在Windows Machine上作为Windows应用程序(Windows 10 Home,21H2)在Windows应用程序中进行调试。

在视图中 - &gt;输出 - &GT; Xamarin热装加载,当我更改“标签”标签时,它说:

[12:34:18 pm]应用XAML热装更新

在“ ViewCell”中进行更改时,应用XAML热加载更新,输出窗口中什么也不会发生。

解决方法: 在写这篇文章时,我注意到一个解决方法:

  • 对“ ViewCell”标签进行更改,
  • 将整个“ ViewCell”标签剪切并保存
  • 热重新加载确实应用了更改,并且内容在应用程序中消失了,
  • 并在“ ViewCell”中粘贴了“ ViewCell”,然后使用更改和Voilà呢

当然,这是我可以忍受的一段时间,但是不必为此应用任何解决方法是很棒的。

I have this XAML

<Label Text="Logfile" FontAttributes="Bold" Margin="0,0,0,10" />
<ListView ItemsSource="{Binding LogEntries}">
  <ListView.ItemTemplate>
    <DataTemplate  x:DataType="model:LogEntity">
      <ViewCell>
        <Grid RowDefinitions="*,*" BackgroundColor="Blue">
        
          <Label Text="{Binding Message}" Grid.Row="0"></Label>
          <Label Text="{Binding  LogTime}" Grid.Row="1"></Label>
        
        </Grid>
      </ViewCell>
    </DataTemplate>
  </ListView.ItemTemplate>
</ListView>

If I change these tags

<Label Text="Logfile" FontAttributes="Bold" Margin="0,0,0,10" />
<ListView ItemsSource="{Binding LogEntries}">

the changes appear immediately in the app. But when I change anything within this tag

<ViewCell>
  <Grid RowDefinitions="*,*" BackgroundColor="Blue">
            
    <Label Text="{Binding Message}" Grid.Row="0"></Label>
    <Label Text="{Binding  LogTime}" Grid.Row="1"></Label>
            
  </Grid>
</ViewCell>

nothing happens.

Are there any known limitations to this? Maybe because it's inside a DataTemplate? I haven't seen any limitation in this regards over here: https://learn.microsoft.com/en-us/visualstudio/xaml-tools/xaml-hot-reload-troubleshooting?view=vs-2022

I am using Visual Studio 2022 Version 17.3.0 Preview 1.1.

My settings in Visual Studio are:

Debugging -> .NET/C++ Hot Reload (Probably not relevant for this context)

Debugging -> XAML Hot Reload

I am debugging as Windows App on a Windows machine (Windows 10 Home, 21H2).

Under View -> Output -> Xamarin Hot Reload, when I make a change to the "Label" tag, it says:

[12:34:18 PM] Applying XAML Hot Reload update

When I make a change within the "ViewCell", nothing happens in the output window.

Workaround:
While writing this, I noticed a workaround:

  • Make changes to the "ViewCell" tag
  • Cut the whole "ViewCell" tag and save
  • Hot Reload does apply the changes and the content disappears in the app
  • Paste the "ViewCell" back with the changes and voilà!

This is certainly something I can live with for a while, but it would be great to not have to apply any workarounds for this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒岛晴空 2025-02-12 20:40:28

问题应该是ListView的视频。如果您使用CollectionView并定义自己的模板,则热重新加载将尽其所能。

您可以在 decection collection vifie collectionvveiew>布局

The problem should be the ViewCell of the ListView. If you use a CollectionView and define your own template, hot reload will work as it should.

You can find an example of CollectionView at Specify CollectionView layout

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文