Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将DynamicSource的值发送到自定义控件C#后端?_C#_Xamarin_Xamarin.forms - Fatal编程技术网

如何将DynamicSource的值发送到自定义控件C#后端?

如何将DynamicSource的值发送到自定义控件C#后端?,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我创建了一个自定义控件: <?xml version="1.0" encoding="UTF-8"?> <Frame xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:Japanese;assembly=Japanese" x:Cla

我创建了一个自定义控件:

<?xml version="1.0" encoding="UTF-8"?>
<Frame xmlns="http://xamarin.com/schemas/2014/forms" 
   xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"          
   xmlns:local="clr-namespace:Japanese;assembly=Japanese" 
   x:Class="Ja.Templates.Button" 
   x:Name="this" 
   Test="{DynamicResource Test}" >
</Frame>

namespace Japanese.Templates
{
    public partial class Button : Frame
    {

        public static readonly BindableProperty TestProperty = 
           BindableProperty.Create(nameof(Test), typeof(string), typeof(Button), 
           default(string), propertyChanged: TestChanged);

        public string Test { get => (string)GetValue(TestProperty); 
                             set => SetValue(TestProperty, value); }

        private static void TestChanged(BindableObject bindable, 
           object oldValue, object newValue)
        {
            var x = 2;
        }

然后控件没有看到更改,当我调试时,它不会转到变量x。

DynamicResource
值将更改时,它不会通知控件。你可以在官方网站上看到更多关于它的信息。我还建议您阅读
BindableProperties


在共享代码示例中,不清楚您想做什么,但是,似乎您应该通过将值存储在
视图模型中来替换
DynamicResource

您好,我使用的是视图模型,但我希望从另一个页面通知控件。我可以在应用程序中以类似于视图模型的方式创建属性吗。类似于公共部分类应用程序:应用程序{公共静态字符串测试,然后让它通知控件或任何正在侦听的人,如果是这样,我怎么做?@Alan2静态属性在我看来是不可绑定的,因此您无法执行上述操作。谢谢,我将尝试以不同的方式执行此操作,并将作为另一个问题记录下来,因为我在这方面也有一些问题。
Application.Current.Resources["Test"] = "X";
Application.Current.Resources["Test"] = "Y";