Xamarin.Forms是一款Microsoft产品,允许从单个共享C#代码库为Android,iOS,Windows和其他应用程序构建本机,跨平台应用程序。
为什么即使我将 Visual Studio 中的构建设置设置为“发布”,我在侧面加载的 UWP 发行版中创建的所有内容都会放置在末尾带有 _test 的文件夹中?是吗
无法清除 Xamarin.Forms Android 中的应用程序缓存
我正在尝试清除/删除我的 Xamarin.forms Android 应用程序的应用程序缓存文件夹。我尝试了不同的代码,但该文件夹仍未被清除。 我做了什么 我通过
如何根据Xamarin表单中collectionView中的值更改行背景颜色
我想根据日期更改collectionView中背景行的颜色。 例如: foreach(myList 中的 var 项目) { if (item.ExpiryDate <= DateTime.Now ) { Mylistrow.
我正在考虑 Xamarin Android 应用程序,实际上我想在我自己的/物理设备上运行我的 Android 应用程序,其中只包含一个轮播页面,所以,这个应用程序在我的中需要多少内存......
是否可以在日历视图中用某种颜色或某种方式永久标记过去的某一天
我有一个简单的Android应用程序,它每天通过预定的本地通知提醒我喝水。为此,我使用 AlarmManager 和 BroadcastRreceiver。然而,通过点击...
如何在 Xamarin Forms 中集成 Apple Pay?
我正在使用xamarin Forms开发应用程序。现在,我需要集成 Apple Pay 我试图通过互联网查找内容,但无法找到有效的解决方案。有人可以建议我吗...
在我正在开发的应用程序之一中,我需要使用自定义地图图钉,并且我已按照 Xamarin https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/ 上的指南进行操作定制撕裂...
我是来自 xamarin 社区工具包 (https://learn.microsoft.com/en-us/xamarin/community-toolkit/) 的 usn MediaElement,我需要旋转它。我试图做到这一点只是改变旋转属性......
我们在 Xamarin.Forms 中进行开发,如果有人有 Xamarin.Forms 分析和崩溃报告的经验/建议,我很感兴趣,我们也最好支持 iOS、Android 和 UWP。 我
毛伊岛/表格:有没有办法像富国银行应用程序的货币字段那样获得所需的效果
基本上,在 Maui/Forms 中使用条目,当我输入时,字段应该从右到左填充。我尝试设置 FlowDirection、TextChanged 事件处理程序,但似乎没有任何效果。不确定...
我的 xamarin 表单项目中有一个如下所示的编辑器。 当我在上面输入消息时,我需要根据字符数增加编辑器的高度。 这是我的完整代码...
我已经在 .Net Maui 中声明了全局样式并尝试从其中一个页面访问它,但它抛出异常 Microsoft.Maui.Controls.Xaml.XamlParseException:位置 10:37。类型转换器
Xamarin:我可以在播放视频时将应用程序静音而背景音乐不会停止吗?
在将我们的 xamarin 应用程序迁移到 MAUI 之前的最后几周,我们的客户提出了一个非常“重要”的改进。目前,当我们在应用程序中播放视频时,背景音乐
在 ValueConverter 中获取 NullReferenceException
我有以下IValueConverter,StringCaseConverter.cs: 内部密封类 StringCaseConverter : IValueConverter { 公共 bool IsUpperCase { 私有获取;放; } 公共对象Conv...
带有 Xamarin Forms 中 XAML 元素参数的构造函数
是否可以使用依赖注入服务使用参数化构造函数创建 XAML 元素?或者还有其他方法来传递依赖关系吗?我想要有一些depe的行为...
如何使用.NET MAUI中的代码访问全局资源字典中定义的样式?
我在 Styles.xaml 文件中定义了样式,例如: <Setter Property="Margin" Value=&q...</desc> <question vote="0"> <p>我在 Styles.xaml 文件中定义了样式,例如:</p> <pre><code><Style x:Key="LabelFiledVerticalStyle" TargetType="Label"> <Setter Property="Margin" Value="0,7,0,0" /> </Style> </code></pre> <h3>方式1</h3> <p>我想从我的代码隐藏文件中访问它,所以我这样做了:</p> <pre><code>var LabelStyle = (Style)Application.Current.Resources["LabelFiledVerticalStyle"]; </code></pre> <p>当我运行该应用程序时,出现以下错误: 字典中不存在资源“LabelFiledVerticalStyle”</p> <h3>方式2通过代码通过key访问资源</h3> <p>我查阅了微软提供的官方文档,找到了其他方法。所以,也尝试过:</p> <pre><code>var hasValue = Resources.TryGetValue("LabelFiledVerticalStyle", out object style); if (hasValue) { var LabelStyle = (Style)style; } </code></pre> <p>在这方面我也得到了 hasValue = false,尽管样式存在于资源字典中。</p> <p>有人知道我们如何从代码隐藏中访问它吗?请告诉我。</p> </question> <answer tick="false" vote="0"> <p><strong>第一种方式</strong></p> <p>如果你想用第一种方式访问样式,我们通常在文件中定义样式<pre><code>App.xaml</code></pre></p> <p>例如,我们可以在<pre><code>App.xaml</code></pre>中定义样式,如下:</p> <pre><code> <?xml version="1.0" encoding="UTF-8"?> <Application xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Styles.App"> <Application.Resources> <ResourceDictionary> <Style x:Key="buttonStyle" TargetType="Button"> <Setter Property="HorizontalOptions" Value="Center" /> <Setter Property="VerticalOptions" Value="CenterAndExpand" /> <Setter Property="BorderColor" Value="Lime" /> <Setter Property="CornerRadius" Value="5" /> <Setter Property="BorderWidth" Value="5" /> <Setter Property="WidthRequest" Value="200" /> <Setter Property="TextColor" Value="Teal" /> </Style> <!-- ContentPage --> <Style TargetType="ContentPage" ApplyToDerivedTypes="True"> <Setter Property="BackgroundColor" Value="WhiteSmoke" /> </Style> <!--define the style of Label here--> <Style x:Key="LabelFiledVerticalStyle" TargetType="Label"> <Setter Property="Margin" Value="0,7,0,0" /> <Setter Property="TextColor" Value="Red" /> </Style> </ResourceDictionary> </Application.Resources> </Application> </code></pre> <p>然后在我们的页面中,我们可以通过代码访问样式:</p> <pre><code>new Label { Text="test label",Style=(Style)Application.Current.Resources ["LabelFiledVerticalStyle"]} </code></pre> <p>使用示例:</p> <pre><code>public class ApplicationStylesPageCS : ContentPage { public ApplicationStylesPageCS () { Title = "Application"; IconImageSource = "csharp.png"; Padding = new Thickness (0, 20, 0, 0); Content = new StackLayout { Children = { new Button { Text = "These buttons", Style = (Style)Application.Current.Resources ["buttonStyle"] }, new Label { Text="test label",Style=(Style)Application.Current.Resources ["LabelFiledVerticalStyle"]} } }; } } </code></pre> <p>有关更多信息,您可以查看文档<a href="https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/styles/xaml/application" rel="nofollow noreferrer">Xamarin.Forms中的全局样式</a>。</p> <p><strong>第二种方式</strong></p> <p>如果您创建一个<pre><code>ResourceDictionary</code></pre>(例如<pre><code>MyResourceDictionary.xaml</code></pre>)并将您的样式添加到<pre><code>ResourceDictionary</code></pre>,如下所示:</p> <p><pre><code>MyResourceDictionary.xaml</code></pre></p> <pre><code><?xml version="1.0" encoding="UTF-8"?> <ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"> <!--define the style of Label here--> <Style x:Key="LabelFiledVerticalStyle" TargetType="Label"> <Setter Property="Margin" Value="0,7,0,0" /> <Setter Property="TextColor" Value="Red" /> </Style> </ResourceDictionary> </code></pre> <p>然后,如果我们想访问样式,我们应该将上面的 <pre><code>ResourceDictionary </code></pre> 添加到页面的 <pre><code>ContentPage.Resources</code></pre> 中。 </p> <pre><code><ContentPage.Resources> <!--add your ResourceDictionary here--> <ResourceDictionary Source="MyResourceDictionary.xaml" /> </ContentPage.Resources> </code></pre> <p>您可以参考这里的示例代码:</p> <p><pre><code>ApplicationStylesPage.xaml</code></pre></p> <pre><code> <?xml version="1.0" encoding="UTF-8"?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Styles.ApplicationStylesPage" Title="Application" IconImageSource="xaml.png"> <ContentPage.Resources> <!--add your ResourceDictionary here--> <ResourceDictionary Source="MyResourceDictionary.xaml" /> <ResourceDictionary> <Style x:Key="buttonStyle" TargetType="Button"> <Setter Property="HorizontalOptions" Value="Center" /> <Setter Property="VerticalOptions" Value="CenterAndExpand" /> <Setter Property="BorderColor" Value="Lime" /> <Setter Property="CornerRadius" Value="5" /> <Setter Property="BorderWidth" Value="5" /> <Setter Property="WidthRequest" Value="200" /> <Setter Property="TextColor" Value="Red" /> </Style> </ResourceDictionary> </ContentPage.Resources> <ContentPage.Content> <StackLayout Padding="0,20,0,0"> <Button Text="application style overrides" Style="{StaticResource buttonStyle}" Clicked="Button_Clicked" /> </StackLayout> </ContentPage.Content> </ContentPage> </code></pre> <p><pre><code>ApplicationStylesPage.xaml.cs</code></pre></p> <p> </p> <pre><code>public partial class ApplicationStylesPage : ContentPage { public ApplicationStylesPage () { InitializeComponent (); } private void Button_Clicked(object sender, System.EventArgs e) { var hasValue = Resources.TryGetValue("LabelFiledVerticalStyle", out object style); if (hasValue) { var LabelStyle = (Style)style; } } } </code></pre> </answer> <answer tick="false" vote="0"> <p>我遇到了类似的问题,解决方案非常有帮助,但有一个警告:</p> <p>在常规的 Maui 应用程序中,资源不会位于 Resources 中,而是位于 App.Current.Resources 中,如果一开始上述解决方案不起作用,请使用此解决方案。</p> </answer> </body></html>
我正在使用 Xamarin 表单编写应用程序。当我使用 popAsync() 离开编辑列表的页面时,我想刷新上一页上的列表,以便显示我的更改......
如何向 .NET Maui 应用程序中的所有按钮添加全局单击事件处理程序?
我有一个 .NET Maui 应用程序,应该将用户事件写入日志文件。我一直在做的是将这段代码放在每个基页或不继承该基页的页面中。 我学会了...
xamarin.forms (android) 无法更新应用程序商店中的应用程序“android:exported”属性缺失
截至今天,某些事情一定发生了变化,因为我们无法在应用程序商店中更新我们的应用程序。 我们在上传时收到此错误: 警告:如果活动、服务或广播接收器使用 Intent fi...
我正在开发一个xamarin表单应用程序,我想添加以显示“正在加载”状态。但我现在就面临这个问题。当我打开该页面时,会显示底部堆栈布局,但它永远不会改变...