我如何知道我正在/使用哪个版本的毛伊岛。我使用了 Visual Studio 安装程序并尝试进行检查,但我无法判断我是否使用的是最初安装的预览版 3,或者是否已成功更新到 GA?
奇怪的是我无法通过搜索找到此信息。:(
我正在尝试更新绑定到 CollectionView 的 ObservableCollection 中的实际字段。
CollectionView 在添加、删除项目时更新得很好,但如果我以编程方式更改列表中的项目则不会。
我从这篇文章中了解到,Observable 集合未更新,我需要实现 INotifyPropertyChanged。
我正在使用 CommunityToolkit.Mvvm 并希望这种魔法能够自动完成,但似乎没有。我没有 C# 知识,不知道如何做我想做的事。有人可以帮我吗:)
https://github.com/gfmoore/TestCollectionBinding有一个存储库
这是我当前的代码:
视图.MyItem.cs
namespace TestCollectionBinding.Views;
public class MyItem
{
public string Name { get; set; }
public string Device { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
ViewModels.MainPageViewModel.cs
using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using TestCollectionBinding.Views;
namespace TestCollectionBinding.ViewModels;
public partial class MainPageViewModel : ObservableObject
{
[ObservableProperty]
public ObservableCollection<MyItem> myItems = new()
{
new MyItem
{ …Run Code Online (Sandbox Code Playgroud) 首先要事。我知道还有其他与此类似的问题,例如use NodeJs Buffer class from client side或 How can I use node.js buffer library in client side javascript
但是,我不明白如何利用该参考来使用 browserify,尽管它已获得批准。
这是我的节点代码:
import { Buffer } from 'buffer/';
Run Code Online (Sandbox Code Playgroud)
我知道这相当于 ES6 中的 require。
我想要这个模块的 javaScript 文件实现,以便我可以简单地使用标准 html 文件参考:
<script src=./js/buffer.js></script>
Run Code Online (Sandbox Code Playgroud)
然后使用它,例如
return new Buffer(temp).toString('utf-8');
Run Code Online (Sandbox Code Playgroud)
这简直就是失败了
Uncaught ReferenceError: Buffer is not defined
Run Code Online (Sandbox Code Playgroud)
无论我如何创建 buffer.js 文件。
因此,使用 browserify 的想法,我尝试使用独立脚本(来自https://www.npmjs.com/package/buffer作为https://bundle.run/buffer@6.0.3)
我创建了一个 test.js 文件并放入
var Buffer = require('buffer/').Buffer
Run Code Online (Sandbox Code Playgroud)
然后运行 browserify 作为
browserify test.js -o buffer.js
Run Code Online (Sandbox Code Playgroud)
以及许多其他变体。我一事无成。我知道我一定做了一些愚蠢的事情,反映出我的无知。也许你可以帮助教育我。
伙计,这就像走过糖蜜:(
好的,我在名为 models 的文件夹中有一个类。我在名为 ViewModels 的文件夹中有一个视图模型,还有一个显示蓝牙连接列表的页面 - 不要兴奋,这只是虚拟数据:叹息
所以这是代码BluetoothPeripheral.cs
namespace TSDZ2Monitor.Models;
public class BluetoothPeripheral
{
public string Name { get; set; }
public string Id { get; set; }
public bool Enabled { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
namespace TSDZ2Monitor.ViewModels;
public partial class BluetoothPeripheralsViewModel : ObservableObject
{
[ObservableProperty]
public ObservableCollection<BluetoothPeripheral> bluetoothPeripherals = new()
{
new BluetoothPeripheral
{
Name = "Heart Rate Monitor",
Id = "12:12:12:12:AB",
Enabled = true
},
new BluetoothPeripheral
{
Name = "Speedometer",
Id = "34:34:34:34:CD",
Enabled = true …Run Code Online (Sandbox Code Playgroud) 所以我有一个弹出菜单,我需要使弹出项目在某些条件下消失。为了帮助我发展我的想法和理解,我有一个包含 6 个项目的弹出窗口,其中之一的标题是蓝牙。我在第一个弹出页面中创建了一个名为 ShowParameters 的按钮。我可以使视图模型中的属性为 true 或 false。这似乎工作正常。我已将蓝牙弹出项目的 IsVisible 属性绑定到此 ShowParameters 属性。这不会在单击按钮时更新 IsVisible 属性。似乎 PropertyChanged?.Invoke 未链接到 Flyout 项目,或者 Flyout 项目未链接到该属性,尽管我可以使其在 xaml 本身中出现或消失。显然,作为一个菜鸟,我做了一些非常愚蠢的事情。有人可以指出我有多愚蠢吗;)
AppShell.xaml
<?xml version="1.0" encoding="UTF-8" ?>
<Shell
x:Class="TSDZ2Monitor.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:sys="clr-namespace:System;assembly=netstandard"
xmlns:local="clr-namespace:TSDZ2Monitor"
xmlns:pages="clr-namespace:TSDZ2Monitor.Pages"
Shell.FlyoutBehavior="Flyout"
FlyoutHeaderBehavior="Default"
FlyoutVerticalScrollMode="Auto"
FlyoutBackgroundColor="{StaticResource FlyoutBackgroundColor}">
<Shell.BindingContext>
<local:ShowParametersViewModel/>
</Shell.BindingContext>
<Shell.FlyoutHeaderTemplate>
<DataTemplate>
<Grid BackgroundColor="{StaticResource FlyoutBackgroundColor}"
HeightRequest="200">
<Image
HeightRequest="200"
Source="bicycle.svg"
Margin="10, 10, 10, 10"
Opacity="0.6" />
<Label Text="TSDZ2 Monitor"
TextColor="White"
FontAttributes="Bold" />
</Grid>
</DataTemplate>
</Shell.FlyoutHeaderTemplate>
<Shell.FlyoutFooterTemplate>
<DataTemplate>
<StackLayout>
<Label Text="TSDZ2"
TextColor="GhostWhite"
FontAttributes="Bold"
HorizontalOptions="Center" />
<Label Text="{Binding Source={x:Static sys:DateTime.Now}, StringFormat='{0:MMMM …Run Code Online (Sandbox Code Playgroud) 所以我正在使用 SQLite、CommunityToolkit.Mvvm.ComponentModel;
我有一个包含朋友表的数据库。我可以将其绑定到 CollectionView。我正在关注https://www.youtube.com/watch?v=8_cqUvriwM8但尝试使用 MVVM 方法。
我可以让它与 SelectionChanged 和事件一起愉快地工作,但不能与 SelectionChangedCommand 一起工作,并且我无法访问列表中的好友项目。
这是相关的xaml
<CollectionView Grid.Row="2"
x:Name="FriendsList"
SelectionMode="Single"
SelectionChangedCommand="{Binding SelectionChangedCommand}"
SelectionChangedCommandParameter="{Binding .}"
SelectionChanged="OnSelectionChanged" >
Run Code Online (Sandbox Code Playgroud)
这是代码的相关部分(我使用 xaml 后面的代码只是为了测试)
public MainPage()
{
InitializeComponent();
this.BindingContext = this; //cool for binding the xaml to the code behind.
}
...
//This works fine (so why do I bother with mvvm?)
public void OnSelectionChanged(Object sender, SelectionChangedEventArgs e)
{
Console.WriteLine("Selection changed click");
Friend f = e.CurrentSelection[0] as Friend;
Console.WriteLine(f.LName);
}
//Can't get this to work, though it …Run Code Online (Sandbox Code Playgroud) 参考之前的问题.Net maui:如何在绑定中引用颜色?
我有一个 CollectionView,绑定到从 SQLite 数据库填充的 ObservableCollection。
我想根据数据库表中保存的颜色字符串显示每一行
但是,我只想将颜色值存储为字符串。
是否可以将此字符串转换为绑定内的颜色或调用函数来执行此操作?
例如:
<Label Text="{Binding Name}"
TextColor="{Binding ConvertStringToColor(ItemColor)}" />
Run Code Online (Sandbox Code Playgroud)
其中 ItemColor 是我的集合模型中的字符串,可以绑定到。
所以我正在学习 xamarin 表单课程,但我正在对其进行调整以与 .net Maui 一起使用。到目前为止,它是一个基本的应用程序,仅构建了弹出外壳。
作者使用的是 autofac,我以前从未听说过或使用过。我按照示例进行操作并得到运行时异常:
Autofac.Core.Activators.Reflection.NoConstructorsFoundException:“找不到类型‘MauiApp4.Resource+Xml’的可访问构造函数。”
我不知道这意味着什么,也不知道如何继续:叹息
(我认为它试图说它无法访问某些东西?我也怀疑与 IContainer 有关?)
哦它
当我尝试在 Visual Studio 2022 社区版的 Android Pixel 5.0 API 30 Android 模拟器上构建和运行应用程序时,会发生这种情况。
它似乎在 Container = builder.Build(); 行崩溃
Autofac使用nuget加载,版本为6.3.0
我不知道我使用的是哪个版本的 .net 或 maui,但它是最新的(我如何获取此信息?)
这是当前(适用?)代码:(它也在我的 github 存储库上https://github.com/gfmoore/MauiApp4B.App/tree/master)
应用程序.xaml.cs
using System.Reflection;
using Autofac;
using IContainer = Autofac.IContainer;
namespace MauiApp4;
public partial class App : Application
{
public static IContainer Container;
public App()
{
InitializeComponent();
//class used for registration
var builder = new ContainerBuilder();
//scan and register all …Run Code Online (Sandbox Code Playgroud) 所以我有一个标签,我想从 mvvm 变量设置文本颜色。
虚拟机
[ObservableProperty]
private string col = "White";
Run Code Online (Sandbox Code Playgroud)
XAML
<Label Text="{Binding Name}"
FontSize="20"
TextColor="{Binding Col}">
Run Code Online (Sandbox Code Playgroud)
所以一般来说 TextColor="White" 效果很好
我尝试过使用 Color 对象 https://learn.microsoft.com/en-us/dotnet/maui/user-interface/graphics/colors
例如
[ObservableProperty]
private Color col = Colors.White;
Run Code Online (Sandbox Code Playgroud)
但我无法让它发挥作用。
我曾希望一个简单的字符串能够工作......哦,我徒劳的希望......
谢谢,G。
编辑:我应该补充一点,我的标签位于 CollectionView 中?
大编辑:它适用于独立标签,即
[ObservableProperty]
private Color col = Colors.White;
Run Code Online (Sandbox Code Playgroud)
所以问题是标签是否在 CollectionView 中。我想知道为什么?
编辑:因为 CollectionView 绑定到 ItemsSource - 啊,真是个假人!