xamarin.forms 相关问题

Xamarin.Forms是一款Microsoft产品,允许从单个共享C#代码库为Android,iOS,Windows和其他应用程序构建本机,跨平台应用程序。

Xamarin 表单:根据字符数增加编辑器高度

我的 xamarin 表单项目中有一个如下所示的编辑器。 当我在上面输入消息时,我需要根据字符数增加编辑器的高度。 这是我的完整代码...

回答 2 投票 0

为什么 .NET-Maui 全局样式不起作用?

我已经在 .Net Maui 中声明了全局样式并尝试从其中一个页面访问它,但它抛出异常 Microsoft.Maui.Controls.Xaml.XamlParseException:位置 10:37。类型转换器

回答 3 投票 0

Xamarin:我可以在播放视频时将应用程序静音而背景音乐不会停止吗?

在将我们的 xamarin 应用程序迁移到 MAUI 之前的最后几周,我们的客户提出了一个非常“重要”的改进。目前,当我们在应用程序中播放视频时,背景音乐

回答 1 投票 0

在 ValueConverter 中获取 NullReferenceException

我有以下IValueConverter,StringCaseConverter.cs: 内部密封类 StringCaseConverter : IValueConverter { 公共 bool IsUpperCase { 私有获取;放; } 公共对象Conv...

回答 2 投票 0

带有 Xamarin Forms 中 XAML 元素参数的构造函数

是否可以使用依赖注入服务使用参数化构造函数创建 XAML 元素?或者还有其他方法来传递依赖关系吗?我想要有一些depe的行为...

回答 2 投票 0

如何使用.NET MAUI中的代码访问全局资源字典中定义的样式?

我在 Styles.xaml 文件中定义了样式,例如: <Setter Property="Margin" Value=&q...</desc> <question vote="0"> <p>我在 Styles.xaml 文件中定义了样式,例如:</p> <pre><code>&lt;Style x:Key=&#34;LabelFiledVerticalStyle&#34; TargetType=&#34;Label&#34;&gt; &lt;Setter Property=&#34;Margin&#34; Value=&#34;0,7,0,0&#34; /&gt; &lt;/Style&gt; </code></pre> <h3>方式1</h3> <p>我想从我的代码隐藏文件中访问它,所以我这样做了:</p> <pre><code>var LabelStyle = (Style)Application.Current.Resources[&#34;LabelFiledVerticalStyle&#34;]; </code></pre> <p>当我运行该应用程序时,出现以下错误: 字典中不存在资源“LabelFiledVerticalStyle”</p> <h3>方式2通过代码通过key访问资源</h3> <p>我查阅了微软提供的官方文档,找到了其他方法。所以,也尝试过:</p> <pre><code>var hasValue = Resources.TryGetValue(&#34;LabelFiledVerticalStyle&#34;, 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> &lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt; &lt;Application xmlns=&#34;http://xamarin.com/schemas/2014/forms&#34; xmlns:x=&#34;http://schemas.microsoft.com/winfx/2009/xaml&#34; x:Class=&#34;Styles.App&#34;&gt;       &lt;Application.Resources&gt;             &lt;ResourceDictionary&gt;                   &lt;Style x:Key=&#34;buttonStyle&#34; TargetType=&#34;Button&#34;&gt;                         &lt;Setter Property=&#34;HorizontalOptions&#34; Value=&#34;Center&#34; /&gt;                         &lt;Setter Property=&#34;VerticalOptions&#34; Value=&#34;CenterAndExpand&#34; /&gt;                         &lt;Setter Property=&#34;BorderColor&#34; Value=&#34;Lime&#34; /&gt;                         &lt;Setter Property=&#34;CornerRadius&#34; Value=&#34;5&#34; /&gt;                         &lt;Setter Property=&#34;BorderWidth&#34; Value=&#34;5&#34; /&gt;                         &lt;Setter Property=&#34;WidthRequest&#34; Value=&#34;200&#34; /&gt;                         &lt;Setter Property=&#34;TextColor&#34; Value=&#34;Teal&#34; /&gt;                   &lt;/Style&gt; &lt;!-- ContentPage --&gt; &lt;Style TargetType=&#34;ContentPage&#34; ApplyToDerivedTypes=&#34;True&#34;&gt; &lt;Setter Property=&#34;BackgroundColor&#34; Value=&#34;WhiteSmoke&#34; /&gt; &lt;/Style&gt; &lt;!--define the style of Label here--&gt; &lt;Style x:Key=&#34;LabelFiledVerticalStyle&#34; TargetType=&#34;Label&#34;&gt; &lt;Setter Property=&#34;Margin&#34; Value=&#34;0,7,0,0&#34; /&gt; &lt;Setter Property=&#34;TextColor&#34; Value=&#34;Red&#34; /&gt; &lt;/Style&gt; &lt;/ResourceDictionary&gt;       &lt;/Application.Resources&gt; &lt;/Application&gt; </code></pre> <p>然后在我们的页面中,我们可以通过代码访问样式:</p> <pre><code>new Label { Text=&#34;test label&#34;,Style=(Style)Application.Current.Resources [&#34;LabelFiledVerticalStyle&#34;]} </code></pre> <p>使用示例:</p> <pre><code>public class ApplicationStylesPageCS : ContentPage       {             public ApplicationStylesPageCS ()             {                   Title = &#34;Application&#34;;                   IconImageSource = &#34;csharp.png&#34;;                   Padding = new Thickness (0, 20, 0, 0);                   Content = new StackLayout {                         Children = {                               new Button { Text = &#34;These buttons&#34;, Style = (Style)Application.Current.Resources [&#34;buttonStyle&#34;] },                               new Label { Text=&#34;test label&#34;,Style=(Style)Application.Current.Resources [&#34;LabelFiledVerticalStyle&#34;]}                         }                   };             }       } </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>&lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt; &lt;ResourceDictionary xmlns=&#34;http://xamarin.com/schemas/2014/forms&#34; xmlns:x=&#34;http://schemas.microsoft.com/winfx/2009/xaml&#34;&gt; &lt;!--define the style of Label here--&gt; &lt;Style x:Key=&#34;LabelFiledVerticalStyle&#34; TargetType=&#34;Label&#34;&gt; &lt;Setter Property=&#34;Margin&#34; Value=&#34;0,7,0,0&#34; /&gt; &lt;Setter Property=&#34;TextColor&#34; Value=&#34;Red&#34; /&gt; &lt;/Style&gt; &lt;/ResourceDictionary&gt; </code></pre> <p>然后,如果我们想访问样式,我们应该将上面的 <pre><code>ResourceDictionary </code></pre> 添加到页面的 <pre><code>ContentPage.Resources</code></pre> 中。 </p> <pre><code>&lt;ContentPage.Resources&gt; &lt;!--add your ResourceDictionary here--&gt; &lt;ResourceDictionary Source=&#34;MyResourceDictionary.xaml&#34; /&gt; &lt;/ContentPage.Resources&gt; </code></pre> <p>您可以参考这里的示例代码:</p> <p><pre><code>ApplicationStylesPage.xaml</code></pre></p> <pre><code> &lt;?xml version=&#34;1.0&#34; encoding=&#34;UTF-8&#34;?&gt; &lt;ContentPage xmlns=&#34;http://xamarin.com/schemas/2014/forms&#34; xmlns:x=&#34;http://schemas.microsoft.com/winfx/2009/xaml&#34; x:Class=&#34;Styles.ApplicationStylesPage&#34; Title=&#34;Application&#34; IconImageSource=&#34;xaml.png&#34;&gt;       &lt;ContentPage.Resources&gt; &lt;!--add your ResourceDictionary here--&gt; &lt;ResourceDictionary Source=&#34;MyResourceDictionary.xaml&#34; /&gt; &lt;ResourceDictionary&gt;                   &lt;Style x:Key=&#34;buttonStyle&#34; TargetType=&#34;Button&#34;&gt;                         &lt;Setter Property=&#34;HorizontalOptions&#34; Value=&#34;Center&#34; /&gt;                         &lt;Setter Property=&#34;VerticalOptions&#34; Value=&#34;CenterAndExpand&#34; /&gt;                         &lt;Setter Property=&#34;BorderColor&#34; Value=&#34;Lime&#34; /&gt;                         &lt;Setter Property=&#34;CornerRadius&#34; Value=&#34;5&#34; /&gt;                         &lt;Setter Property=&#34;BorderWidth&#34; Value=&#34;5&#34; /&gt;                         &lt;Setter Property=&#34;WidthRequest&#34; Value=&#34;200&#34; /&gt;                         &lt;Setter Property=&#34;TextColor&#34; Value=&#34;Red&#34; /&gt;                   &lt;/Style&gt;             &lt;/ResourceDictionary&gt;       &lt;/ContentPage.Resources&gt;       &lt;ContentPage.Content&gt;             &lt;StackLayout Padding=&#34;0,20,0,0&#34;&gt;                   &lt;Button Text=&#34;application style overrides&#34; Style=&#34;{StaticResource buttonStyle}&#34; Clicked=&#34;Button_Clicked&#34; /&gt;             &lt;/StackLayout&gt;       &lt;/ContentPage.Content&gt; &lt;/ContentPage&gt; </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(&#34;LabelFiledVerticalStyle&#34;, 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>

回答 0 投票 0

Xamarin - PopAsync() 之后刷新列表

我正在使用 Xamarin 表单编写应用程序。当我使用 popAsync() 离开编辑列表的页面时,我想刷新上一页上的列表,以便显示我的更改......

回答 4 投票 0

如何向 .NET Maui 应用程序中的所有按钮添加全局单击事件处理程序?

我有一个 .NET Maui 应用程序,应该将用户事件写入日志文件。我一直在做的是将这段代码放在每个基页或不继承该基页的页面中。 我学会了...

回答 1 投票 0

xamarin.forms (android) 无法更新应用程序商店中的应用程序“android:exported”属性缺失

截至今天,某些事情一定发生了变化,因为我们无法在应用程序商店中更新我们的应用程序。 我们在上传时收到此错误: 警告:如果活动、服务或广播接收器使用 Intent fi...

回答 2 投票 0

活动指示器不会更改可见属性并显示整个页面

我正在开发一个xamarin表单应用程序,我想添加以显示“正在加载”状态。但我现在就面临这个问题。当我打开该页面时,会显示底部堆栈布局,但它永远不会改变...

回答 1 投票 0

使用更新的 Intune SDK,LoginAndEnrollAccount(emailText) 不会提示电子邮件和密码

我们的应用程序是带有 Xamarin 表单的 Intune 应用程序。 身份验证由 Intune SDK 默认处理。 应用程序不使用 ADAL 也不使用 MSAL。 Intune SDK 更新后,LoginAndEnrollAccount 不会

回答 1 投票 0

Xamarin.Forms 如何让 Intent 发挥作用?

我有一个 Xamarin.Forms 解决方案,但发现很难实现 Intent 类,因为该库是 Android.Content 的一部分。 我的解决方案有 2 个项目。项目 1 和项目 1.Android。 我...

回答 1 投票 0

无法分配属性“Converter”:属性不存在,或不可分配,或值和属性之间的类型不匹配

我正在使用 Xamarin.Forms 和 MvvmCross 编写一个应用程序。我的转换器有问题。在我的核心项目中: 公共类 BoolInverseValueConverter :MvxValueConverter {

回答 5 投票 0

Xamarin.forms 可以针对 android 14 ( sdk 34) 吗?

我正在尝试更新我的应用程序以按照官方公告(https://dotnet.microsoft.com/en-us/platform/support/policy/xamarin)指定的 Android 34 为目标 我尝试直接将清单文件更改为

回答 1 投票 0

Xamarin Essentials 的 FilePicker 不允许在 iOS 上选择任何文件

我需要在我的应用程序中导入 CSV/SQLite3 文件以从以前的离线备份恢复设置。我使用 Xamarin.Essentials.FilePicker,它在 Android 上完美运行,但是在 iOS 上尝试时......

回答 1 投票 0

如何在 XAML 中将 FontAttributes 设置为粗体和斜体?

在 Xamarin.Forms 中,如何将 XAML 中的 FontAttributes 设置为粗体和斜体? 例子: <Setter Property="FontAttributes" Value="Bold" /> <...</desc> <question vote="16"> <p>在 Xamarin.Forms 中,如何将 <pre><code>FontAttributes</code></pre> 内的 <pre><code>XAML</code></pre> 设置为 <strong>粗体</strong> 和 <strong>斜体</strong>?</p> <p><strong>示例:</strong></p> <pre><code> &lt;Style TargetType=&#34;Label&#34;&gt; &lt;Setter Property=&#34;FontAttributes&#34; Value=&#34;Bold&#34; /&gt; &lt;Setter Property=&#34;FontAttributes&#34; Value=&#34;Italic&#34; /&gt; &lt;/Style&gt; </code></pre> </question> <answer tick="true" vote="30"> <pre><code>&lt;Style TargetType=&#34;Label&#34;&gt; &lt;Setter Property=&#34;FontAttributes&#34; Value=&#34;Bold, Italic&#34; /&gt; &lt;/Style&gt; </code></pre> <p><pre><code>FontAttributes</code></pre>是一个Flag,因此您可以传递多个值。</p> </answer> <answer tick="false" vote="4"> <p>如果有人正在寻找代码隐藏解决方案:</p> <pre><code>element.FontAttributes = FontAttributes.Bold | FontAttributes.Italic; </code></pre> </answer> <answer tick="false" vote="3"> <p>在值字段中继续使用逗号分隔它们。 </p> <pre><code>&lt;Style TargetType=&#34;Label&#34;&gt; &lt;Setter Property=&#34;FontAttributes&#34; Value=&#34;Bold, Italic&#34;/&gt; &lt;/Style&gt; </code></pre> <p>请务必查看 <a href="http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/fonts/" rel="nofollow">http://developer.xamarin.com/guides/cross-platform/xamarin-forms/working-with/fonts/</a></p> </answer> <answer tick="false" vote="0"> <pre><code>FontAttributes=&#34;Bold, Italic&#34; </code></pre> <p><a href="https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/fonts" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/text/fonts</a></p> </answer> </body></html>

回答 0 投票 0

可绑定属性问题屏蔽行为

我正在尝试实施一个掩码来调整我的电话号码的输入,但我正在收集来自该国家/地区的行为 用户选择的。 我正在尝试实施一个掩码来调整我的电话号码的输入,但我正在收集来自该国家/地区的行为 用户选择的。 <Entry Keyboard="Numeric" Placeholder="Telephone Number" BackgroundColor="#FFFFFF" IsSpellCheckEnabled="True"> <Entry.Behaviors> <behaviors:MaskedBehavior Mask="{Binding SelectedCountry.Mask}" /> </Entry.Behaviors> </Entry> 但是当值发挥作用时,行为就会出现问题。 public class MaskedBehavior : Behavior<Entry> { private string _mask = "(XXX) XXXX XXXX"; public static readonly BindableProperty MaskProperty = BindableProperty.Create("Mask", typeof(string), typeof(MaskedBehavior), null, BindingMode.TwoWay, null, propertyChanged: OnItemsSourceChanged); static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue) { var control = (MaskedBehavior)bindable; control.Mask = (string)newValue; } public string Mask { get { return (string)GetValue(MaskProperty); } set { SetValue(MaskProperty, _mask); SetPositions(); } } private void OnEntryTextChanged(object sender, TextChangedEventArgs args) { var entry = sender as Entry; var text = entry.Text; if (string.IsNullOrWhiteSpace(text) || _positions == null) return; if (text.Length > _mask.Length) { entry.Text = text.Remove(text.Length - 1); return; } foreach (var position in _positions) if (text.Length >= position.Key + 1) { var value = position.Value.ToString(); if (text.Substring(position.Key, 1) != value) text = text.Insert(position.Key, value); } if (entry.Text != text) entry.Text = text; } protected override void OnAttachedTo(Entry entry) { entry.TextChanged += OnEntryTextChanged; base.OnAttachedTo(entry); } protected override void OnDetachingFrom(Entry entry) { entry.TextChanged -= OnEntryTextChanged; base.OnDetachingFrom(entry); } IDictionary<int, char> _positions; void SetPositions() { if (string.IsNullOrEmpty(Mask)) { _positions = null; return; } var list = new Dictionary<int, char>(); for (var i = 0; i < Mask.Length; i++) if (Mask[i] != 'X') list.Add(i, Mask[i]); _positions = list; } 源列表是这样的,我只是编造了一些东西,但在我要修复为正确的行为之后。 **Xaml** <Picker HeightRequest ="40" WidthRequest="300" Title="Country/Region" ItemsSource="{Binding Countries}" ItemDisplayBinding="{Binding CountryName}" SelectedItem="{Binding SelectedCountry}" **C#** static CountriesData() { Countries = new List<Country>(); Countries.Add(new Country { Id = "93", CountryName = "Afghanistan (+93)", Mask = "(XXX) XXXX XXXX" }); Countries.Add(new Country { Id = "335", CountryName = "Albania (+355)", Mask = "(XXX) XXXX XXX" }); } 如果有人可以帮忙=) 抱歉,这是我的第一个项目,如果我没有以正确的方式表达我的意思=/ 创建 BehaviorBase 来更新您的 behavior。 public class BehaviorBase<T> : Behavior<T> where T : BindableObject { #region Properties public T AssociatedObject { get; private set; } #endregion #region NormalMethods private void OnBindingContextChanged(object sender, EventArgs e) { OnBindingContextChanged(); } #endregion #region Overrides protected override void OnAttachedTo(T bindable) { base.OnAttachedTo(bindable); AssociatedObject = bindable; if (bindable.BindingContext != null) { BindingContext = bindable.BindingContext; } bindable.BindingContextChanged += OnBindingContextChanged; } protected override void OnDetachingFrom(T bindable) { base.OnDetachingFrom(bindable); bindable.BindingContextChanged -= OnBindingContextChanged; AssociatedObject = null; } protected override void OnBindingContextChanged() { base.OnBindingContextChanged(); BindingContext = AssociatedObject.BindingContext; } #endregion } 让你的MaskedBehavior继承BehaviorBase。 public class MaskedBehavior : BehaviorBase<Entry> { …….. } 和你的用法一样。 我已经将整个项目上传到GitHub上,大家可以下载参考。 https://github.com/WendyZang/Test/tree/master/Behavior 能否分享一下完整的解决方案(github项目已经不存在了)

回答 2 投票 0

如何在Xamarin中实现类似的内部HTML功能

包含文本和超链接的问题 在上图中,我们可以看到我们同时拥有文本和图片,我们使用 Angular 中的innerhtml 实现了此功能

回答 1 投票 0

.NET MAUI 工具包扩展器

我有Xamarin。表格项目。在该项目中,我有社区工具包 nuget,使用此包我在扩展器中添加了 CollapseAnimationLength 和 ExpandAnimationLength 属性。现在我要走了...

回答 1 投票 0

Xamarin Forms 在 API33 上读取和写入外部存储问题

曾经针对 Android 12 的 Xamarin Forms 应用程序。我所做的只是更改为针对 Android 13 (API33),当我这样做时,我无法再使用 READ_EXTERNAL_STORAGE 或 WRITE_EXTERNAL_S...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.