标签: binding

WPF:使用TemplateBinding将整数绑定到TextBlock

我在WPF中有一个自定义控件.在这我有一个DependencyProperty类型int.在自定义控件的模板中我有一个TextBlock,我想在中显示整数的值TextBlock.但我无法让它发挥作用.

我正在使用TemplateBinding.如果我使用相同的代码,但是改变的类型DependencyProperty,以string正常工作.但我真的希望它是我的应用程序其余部分工作的整数.

我怎样才能做到这一点?

我编写了简化的代码来显示问题.首先是自定义控件:

public class MyCustomControl : Control
{
    static MyCustomControl()
    {
        DefaultStyleKeyProperty.OverrideMetadata(typeof(MyCustomControl), new FrameworkPropertyMetadata(typeof(MyCustomControl)));

        MyIntegerProperty = DependencyProperty.Register("MyInteger", typeof(int), typeof(MyCustomControl), new FrameworkPropertyMetadata(0));
    }


    public int MyInteger
    {
        get
        {
            return (int)GetValue(MyCustomControl.MyIntegerProperty);
        }
        set
        {
            SetValue(MyCustomControl.MyIntegerProperty, value);
        }
    }
    public static readonly DependencyProperty MyIntegerProperty;
}
Run Code Online (Sandbox Code Playgroud)

这是我的默认模板:

<Style TargetType="{x:Type local:MyCustomControl}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:MyCustomControl}">
                <Border BorderThickness="1" CornerRadius="4" BorderBrush="Black" Background="Azure">
                    <StackPanel Orientation="Vertical">
                        <TextBlock Text="{TemplateBinding MyInteger}" HorizontalAlignment="Center" …
Run Code Online (Sandbox Code Playgroud)

wpf xaml binding controltemplate

15
推荐指数
1
解决办法
6759
查看次数

如果data为null,如何隐藏stringformat

如何在数据不存在时隐藏字符串格式.请考虑此示例

<TextBlock Text="{Binding Amount, StringFormat=Total: {0:C}}" />
Run Code Online (Sandbox Code Playgroud)

在这种情况下,如果Amount为null,那么它将只显示Total:.如果Amount为null或为空,如何隐藏它

data-binding wpf binding string-formatting targetnullvalue

15
推荐指数
3
解决办法
1万
查看次数

DataGrid创建RadioButton列

我有绑定到DataGrid的对象.我创建了一个绑定到对象的Is Default属性的单选按钮列.

当应用程序启动时,正确的项目显示为默认值,但是绑定随后不会更新.我想要的行为是用户检查一个单选框并使该对象成为默认值.

        <DataGrid CanUserAddRows="False" AutoGenerateColumns="False" Name="TEst" >
        <DataGrid.Columns >
            <DataGridTextColumn Header="Value" Binding="{Binding Path=Name, Mode=OneTime}"/>

            <DataGridTemplateColumn Header="Is Default">
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <RadioButton GroupName="Test" IsChecked="{Binding IsDefault}" />
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>

        </DataGrid.Columns>
    </DataGrid>

 private class Test : INotifyPropertyChanged
    {
        public string Name
        {
            get;
            set;
        }
        bool isDefult;
        public bool IsDefault
        {
            get
            {
                return isDefult;
            }
            set
            {
                isDefult = value;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }

    public MainWindow()
    {
        this.InitializeComponent();
        Test[] ya = new Test[] { new Test { Name …
Run Code Online (Sandbox Code Playgroud)

.net wpf binding .net-4.0 wpfdatagrid

15
推荐指数
1
解决办法
1万
查看次数

事件绑定意味着什么?

事件绑定意味着什么?每当我在互联网上搜索时,我总是会遇到这个词,无论我试图寻找什么意思,它对我来说仍然含糊不清@ _ @前一段时间,在阅读一些关于JavaScript的博客时我看到人们使用这个神圣的词我不能把握.

javascript jquery events binding closures

15
推荐指数
3
解决办法
8354
查看次数

绑定到另一个应用程序的服务

我写了两个应用程序(目标姜饼).让我们说app1和app2.App1有两个以"BOOT_COMPLETED"开头的服务,它们以返回值START_STICKY开头.它们在不同的线程中运行.使长话短说.其中一项服务是监视串行端口上的传入数据(一种代理,用于与串行端口另一端的接口通信的应用程序).另一个让听众观看一些系统状态并等待来自其他应用程序的一些"指令".我知道它们运行良好,因为它们列在正在运行的服务中,并且我添加了一些代码,当某些特定数据来自串行端口时,它会强制它们执行某些操作.

现在的问题是:我写了app2.它尝试绑定到app1中的某个服务.我使用了android-developper文档,并在app1和app2中的服务之间实现了双向通信.由于我只需要发送少量非常简单的数据,因此我建议使用信使.我基本上只使用"what,arg1和arg2"我没有使用AIDL接口,因为文档建议.

这是androidmanifest在app1中声明服务的部分我也尝试绑定.

    <service android:name=".ModemWatcherService"
              android:label="@string/app_name"
              android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
            <!-- Service name -->
            <action android:name="com.admetric.modemwatcher.Service" />
        </intent-filter>
    </service>
Run Code Online (Sandbox Code Playgroud)

然后,以下是在app1中处理此问题的几种方法:

    @Override
public IBinder onBind(Intent intent) {
    Log.d(TAG, "entering onBind");
    return mMessenger.getBinder();
}

/**
 * Handler of incoming messages from clients.
 */
class IncomingHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
        String logMessage = "Received meaasge what= %d, arg1= %d, arg2= %d" + String.valueOf(msg.what) + String.valueOf(msg.arg1) + String.valueOf( msg.arg2);
        Log.d(TAG, logMessage);
        switch (msg.what) …
Run Code Online (Sandbox Code Playgroud)

binding android android-service

15
推荐指数
1
解决办法
1万
查看次数

Boost.python与Cython for C++/python接口

我知道这已被问了一千次,但是我需要选择一个可以将C++函数和方法暴露给python的库.

考虑到我的应用程序,主要是科学(矩阵)库,以及python生成器的成熟度,支持可用性和性能,我遇到了两个选项:

  • 用Cython
  • Boost.Python的

我已经消除了(出于好的或坏的原因)其他选项,如SWIG,SIP,Pybindgen,......

关于那2个图书馆的任何建议?任何具有杀手功能的东西?

我的项目有名称空间,嵌套类,回调等.

谢谢

c++ python binding cpython boost-python

15
推荐指数
1
解决办法
4040
查看次数

是否可以在XAML中的TemplateBinding上使用转换器?

我正在构建一个按钮样式,它依赖于将颜色画笔转换为较暗的阴影来创建阴影.在常规的XAML中,我有一个转换器,而不是我在绑定上使用的转换器完美地工作:

BorderBrush="{Binding Background, Converter={StaticResource ColourBrushToDarker}}"
Run Code Online (Sandbox Code Playgroud)

但我不能让转换器在样式定义中使用TemplateBinding.有办法吗?Visual Studio只允许在TemplateBinding上使用转换器.

我试过以下没有运气:

Background="{Binding Converter={StaticResource ColourBrushToDarker}, ConverterParameter={Binding Path=Background}}"/>
Run Code Online (Sandbox Code Playgroud)

(我已尝试使用TemplateBinding替换Binding以及其他几个迭代的上述行)

可以这样做吗?我想到的另一件事是用C#编写一个执行转换的属性,但是一个样式没有代码隐藏文件.

我之后的结果是能够创建一个比Background属性更暗的新画笔,因此按钮的阴影总是比它的主背景颜色稍暗.

xaml binding styles converter templatebinding

15
推荐指数
1
解决办法
4047
查看次数

如何绑定反布尔值,JavaFX

我的目标是绑定这两个属性,例如何时checkbox被选中然后paneWithControls被启用,反之亦然.

CheckBox checkbox = new CheckBox("click me");
Pane paneWithControls = new Pane();

checkbox.selectedProperty().bindBidirectional(paneWithControls.disableProperty());
Run Code Online (Sandbox Code Playgroud)

然而,这个代码与我想要的相反.我需要像反布尔绑定这样的东西.是否有可能或者我必须制定一个方法来处理它?

java binding boolean javafx-8

15
推荐指数
1
解决办法
1万
查看次数

为什么Ruby调试器返回的值不同于运行时的代码?

看到这个简单的Ruby类:

require 'byebug'

class Foo
  def run
    byebug

    puts defined?(bar)
    puts bar.inspect

    bar = 'local string'

    puts defined?(bar)
    puts bar.inspect
  end

  def bar
    'string from method'
  end
end

Foo.new.run
Run Code Online (Sandbox Code Playgroud)

运行此类时,可以在调试器的控制台中观察到以下行为:

    $ ruby byebug.rb

    [2, 11] in /../test.rb
        2:
        3: class Foo
        4:   def run
        5:     byebug
        6:
    =>  7:     puts defined?(bar)
        8:     puts bar.inspect
        9:
       10:     bar = 'local string'
       11:
Run Code Online (Sandbox Code Playgroud)

在断点处,调试器返回以下值:

    (byebug) defined?(bar)
    "local-variable"
    (byebug) bar.inspect
    "nil"
Run Code Online (Sandbox Code Playgroud)

请注意 - 尽管调试器的断点符合要求#5- 它已经知道将bar在行#10中定义一个局部变量,该局部变量将影响该方法bar,并且调试器实际上不再能够调用该 …

ruby debugging binding byebug

15
推荐指数
1
解决办法
352
查看次数

如何在WPF XAML中的多绑定中使用stringformat

如您所知,StringFormat对于WPF中的数据表示非常重要.我的问题是如何在WPF中进行多重绑定时使用StringFormat?

如果我举一个非常简单的例子:

我们有变量,它们是A和B,其值为10.255555和25.6999999

我们想要展示它们10.2,25.6吗?

我怎么能用multibinding做到这一点?通常,它与ValueConverter一块蛋糕

任何有关此主题的帮助和想法都将受到高度赞赏

wpf xaml binding wpf-controls

14
推荐指数
3
解决办法
2万
查看次数