在下面的方法中,我只希望result在为结果赋值后对变量进行空检查。我认为现在发生的情况是,有时空检查是在FilePicker.PickAsync()完成之前发生的,因此结果尚未分配值。相反,我只希望在用户选择文件后进行空检查。
private async void PickFileButton_Clicked(object sender, EventArgs e)
{
try
{
Console.WriteLine("checkpoint1");
FileResult result = await FilePicker.PickAsync(new PickOptions
{
FileTypes = new FilePickerFileType(
new Dictionary<DevicePlatform, IEnumerable<string>>
{
{ DevicePlatform.iOS, new[] { "public.item" } },
{ DevicePlatform.Android, new[] { "*/*" } },
{ DevicePlatform.WinUI, new[] { "*/*" } },
{ DevicePlatform.MacCatalyst, new[] { "public.item" } }
})
}); ;
Console.WriteLine("checkpoint2");
if (result.FileName != null)
{
filePath = result.FullPath;
FilePathLabel.Text = filePath;
Console.WriteLine(FilePathLabel.Text);
}
}
catch (Exception ex) …Run Code Online (Sandbox Code Playgroud) 这是我的字符串:
public string EmptyViewText { get; set; } = "Please input a bin id first!*";
Run Code Online (Sandbox Code Playgroud)
我有一个简单的命令:
public async Task Entry(string barcode)
{
MainThread.BeginInvokeOnMainThread(() =>
{
EmptyViewText = "Loading data...*";
OnPropertyChanged();
});
}
Run Code Online (Sandbox Code Playgroud)
这是触发的。
这是我的课:
public partial class BinViewModel : ObservableObject
Run Code Online (Sandbox Code Playgroud)
绑定本身有效,正如我确实看到我的价值观一样。但是当我更改代码中的值时,什么也没有发生。
绑定非常简单:
<Label Text="{Binding EmptyViewText}" />
Run Code Online (Sandbox Code Playgroud)
然而,如果我禁用该字符串并重新启用它(重新渲染它),它确实会显示新的和更正的文本。
这里有什么问题?
在 Azure DevOps 构建管道中构建我的 .NET 8 iOS MAUI 应用程序时,它抱怨我没有使用最新的 Xcode。
ILLink : iOS error IL7000: An error occured while executing the custom linker steps. Please review the build log for more information. [/Users/runner/work/1/s/MyProject/MyProject.csproj::TargetFramework=net8.0-iOS]
/Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/UIKit/UIApplication.g.cs(95): error MT4162: The type 'UIKit.UISceneSessionActivationRequest' (used as a parameter in UIKit.UIApplication.ActivateSceneSession) is not available in iOS 16.4 (it was introduced in iOS 17.0). Please build with a newer iOS SDK (usually done by using the most recent version of Xcode). [/Users/runner/work/1/s/MyProject/MyProject.csproj::TargetFramework=net8.0-iOS]
ILLINK : error MT2362: The …Run Code Online (Sandbox Code Playgroud) 我们知道,没有直接的方法可以在 MAUI 中创建 WPF 应用程序,是否有其他方法可以使用 .NET MAUI 创建 WPF 应用程序?
我想将点击手势识别器与 ICommand 一起使用,这意味着使用 ViewModel 而不是后面的代码。
我正在通过后面的代码使手势识别器工作,如下所示
主页.xaml
<CollectionView Margin="10,0,10,0"
ItemSizingStrategy="MeasureAllItems"
ItemsLayout="VerticalList"
VerticalScrollBarVisibility="Always"
ItemsSource="{Binding QuestionPacks}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="model:QuestionPack">
<Frame Margin="5"
CornerRadius="10">
<Frame.GestureRecognizers>
<TapGestureRecognizer
Tapped="TapGestureRecognizer_Tapped"/>
<TapGestureRecognizer
NumberOfTapsRequired="2"
Tapped="TapGestureRecognizer_Tapped_1"/>
</Frame.GestureRecognizers>
<VerticalStackLayout Margin="5">
<Label Text="{Binding Topic}" />
<Label Text="{Binding TopicId}" />
</VerticalStackLayout>
</Frame>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Run Code Online (Sandbox Code Playgroud)
请注意x:DataType=model:QuestionPack数据模板中的 。
主页.xaml.cs
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
var selectedItem = ((VisualElement)sender).BindingContext as QuestionPack;
if (selectedItem == null)
return;
LoadingQuestions.IsRunning = true;
LoadingQuestions.IsEnabled = true;
await Shell.Current.GoToAsync($"{nameof(QuestionsPage)}?topicSelected={selectedItem.TopicId}");
LoadingQuestions.IsRunning = false;
LoadingQuestions.IsEnabled = false; …Run Code Online (Sandbox Code Playgroud) 我正在尝试添加启动画面,如文档中所述:
<MauiSplashScreen Include="Resources\appsplash.svg" Color="#fff" />
Run Code Online (Sandbox Code Playgroud)
资源位于具有“MauiSplashScreen”构建操作的适当目录中
在 Windows 上可以正常调试,但尝试在 Android 上构建/调试会出现以下错误:
Error APT2061 failed linking file resources.
Error APT2260 resource drawable/appsplash (aka appname:drawable/appsplash) not found.
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
iOS MAUI 应用程序(远程设备)的构建版本失败,并显示以下错误消息:
代码MSB3191 说明无法创建目录“obj/Release/net6.0-ios/ios-arm64//stripped/Microsoft.Extensions.DependencyInjection.Abstractions.dllDevelop\Test\MauiApp1\obj\Release\net6.0-ios\ios -arm64\链接”。指定的路径、文件名或两者都太长。完全限定文件名必须少于 260 个字符,目录名必须少于 248 个字符。 文件C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\15.4.446-ci.-release-6-0-4xx.446\targets\Xamarin.Shared.Sdk.targets 第751行
这是一个从模板“.NET MAUI App”创建的新项目 - 我刚刚更改了应用程序 ID 和配置文件。Windows 10,全新安装 Microsoft Visual Studio Community 2022(64 位)- 当前版本 17.3.5。使用 Xcode 13.3.1 连接到远程 Mac。
iOS(本地设备或远程设备)的调试版本可以。其他平台(Android、Windows)的发布版本没问题...
有人对如何解决这个问题有任何想法吗?
我创建了一个 MAUI 应用程序,在视图模型中我有一个ObservableCollection存储位置。然后这些将显示在 UI 上的图表上。但位置的计算需要花费大量时间,因此我在另一个线程上进行计算以保持 UI 畅通。当我计算位置时,我通过调用Application.Current.Dispatcher.Dispatch方法将其添加到新线程上的集合中,如下所示:
Task.Run(() =>
{
for (int i = 0; i < 1000; i++)
{
Application.Current.Dispatcher.Dispatch(() =>
{
myObservableCollection.Add(new Pos() { X = i, Y = i }));
}
}
}
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我想避免每次迭代中不断的线程切换,所以我想出了这个:
Task.Run(() =>
{
List<Pos> test = new List<Pos>();
for (int i = 0; i < 1000; i++)
{
test.Add(new Pos() { X = i, Y = i }));
}
Application.Current.Dispatcher.Dispatch(() =>
{
myObservableCollection= new ObservableCollection<Pos>(test);
});
}
Run Code Online (Sandbox Code Playgroud)
因此,我创建了列表,并且仅在准备好时才将其传递给可观察集合,以避免线程切换。但这个解决方案根本没有更新用户界面,并且在第一个解决方案完美运行的同时什么也没有出现。为什么第二个不起作用?
我正在做我的项目,遇到了一个问题。我不知道如何显示List.
隐藏代码:
public ObservableCollection<GameResult> GameResultsToShow { get; set; }
= new ObservableCollection<GameResult>();
public void SortResults()
{
List<GameResult> SortedGameResults; //to bind
if (gameOption.gameType == GameType.Time)
SortedGameResults
= GameResults
.FindAll(
x => x.gameOption.gameLevel == gameOption.gameLevel
&& x.gameOption.gameType == gameOption.gameType)
.OrderBy(x => x.points)
.ToList();
else
SortedGameResults
= GameResults
.FindAll(
x => x.gameOption.gameLevel == gameOption.gameLevel
&& x.gameOption.gameType == gameOption.gameType)
.OrderBy(x => x.Time)
.ToList();
var GameResultsToShow = new ObservableCollection<GameResult>(SortedGameResults);
}
Run Code Online (Sandbox Code Playgroud)
XML:
<CollectionView
ItemsSource="{Binding GameResultsToShow }"
BackgroundColor="PapayaWhip"
Margin="10"
Grid.Row="5"
Grid.ColumnSpan="3"
HorizontalOptions="Center">
<CollectionView.ItemTemplate>
<DataTemplate>
<TextCell …Run Code Online (Sandbox Code Playgroud) maui ×10
c# ×5
.net-maui ×3
ios ×3
.net ×2
.net-8.0 ×1
android ×1
async-await ×1
azure-devops ×1
data-binding ×1
list ×1
task ×1
wpf ×1
xamarin ×1
xamarin.ios ×1
xcode ×1