我有类似以下帖子的问题:
Silverlight DataGridTextColumn绑定可见性
我需要根据ViewModel中的值对Silverlight DataGrid中的列进行可见/折叠.为此,我尝试将Visibility属性绑定到ViewModel.但是我很快发现Visibility属性不是DependencyProperty,因此无法绑定.
为了解决这个问题,我尝试将自己的DataGridTextColumn子类化.有了这个新的类,我创建了一个DependencyProperty,最终推动更改DataGridTextColumn.Visibility财产.如果我没有数据绑定,这很有效.在我数据绑定到新属性的那一刻,它失败了,带有AG_E_PARSER_BAD_PROPERTY_VALUE异常.
public class MyDataGridTextColumn : DataGridTextColumn
{
#region public Visibility MyVisibility
public static readonly DependencyProperty MyVisibilityProperty =
DependencyProperty.Register("MyVisibility", typeof(Visibility), typeof(MyDataGridTextColumn), new PropertyMetadata(Visibility.Visible, OnMyVisibilityPropertyChanged));
private static void OnMyVisibilityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var @this = d as MyDataGridTextColumn;
if (@this != null)
{
@this.OnMyVisibilityChanged((Visibility)e.OldValue, (Visibility)e.NewValue);
}
}
private void OnMyVisibilityChanged(Visibility oldValue, Visibility newValue)
{
Visibility = newValue;
}
public Visibility MyVisibility
{
get { return (Visibility)GetValue(MyVisibilityProperty); }
set { SetValue(MyVisibilityProperty, value); }
}
#endregion public Visibility …Run Code Online (Sandbox Code Playgroud) 好吧,我必须在这里冻结大脑......
我有一个包含6个项目的ComboBox,我正在尝试将所选项目绑定到整数值.它不起作用,我怀疑它是因为ComboBoxItem是字符串.我不想在代码后面填写一个列表来填充这个小盒子,所以在xaml中是否有一种方法可以告诉组合框架它们是否保持整数?喜欢的东西<x:Int>2</x:Int>可能?
XAML:
<ComboBox SelectedItem="{Binding SavedPrintTicket.PagesPerSheet}">
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>6</ComboBoxItem>
<ComboBoxItem>8</ComboBoxItem>
<ComboBoxItem>16</ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud) 我正在研究一个大型的WPF项目,在调试期间,我的输出窗口充满了这些烦人的警告:
System.Windows.Data信息:10:无法使用绑定检索值,并且不存在有效>回退值; 使用默认值. BindingExpression:路径= HorizontalContentAlignment; 的DataItem = NULL; target元素是' ComboBoxItem '(Name =''); target属性是'HorizontalContentAlignment'(类型>'HorizontalAlignment')
在具体示例中,ComboBoxItem以这种方式设置样式:
<Style x:Key="{x:Type ComboBoxItem}" TargetType="{x:Type ComboBoxItem}">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border
Name="bd"
Padding="4,4,4,4"
SnapsToDevicePixels="True"
CornerRadius="2,2,2,2">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="true">
<Setter TargetName="bd" Property="Background" Value="{StaticResource MediumBrush}"/>
<Setter TargetName="bd" Property="Padding" Value="4,4,4,4"/>
<Setter TargetName="bd" Property="CornerRadius" Value="2,2,2,2"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Run Code Online (Sandbox Code Playgroud)
我知道问题是由ComboBoxItem的默认主题定义生成的,其中包含以下内容:
<Setter Property="Control.HorizontalContentAlignment">
<Setter.Value>
<Binding Path="HorizontalContentAlignment" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ItemsControl, AncestorLevel=1}" />
</Setter.Value>
</Setter>
Run Code Online (Sandbox Code Playgroud)
但我也认为使用
<Setter Property="OverridesDefaultStyle" …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个具有要绑定的依赖项属性的用户控件.在内部我有一个ComboBox绑定到这些相同属性的绑定,但绑定只能以一种方式工作.在ComboBox从罢了ItemsSource,但SelectedItem没有更新回到视图模型,我结合.
一个简化的例子:
这是与用户控件绑定的视图模型:
public class PeopleViewModel : INotifyPropertyChanged
{
public PeopleViewModel()
{
People = new List<string>( new [] {"John", "Alfred","Dave"});
SelectedPerson = People.FirstOrDefault();
}
public event PropertyChangedEventHandler PropertyChanged;
private IEnumerable<string> _people;
public IEnumerable<string> People
{
get { return _people; }
set
{
_people = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("People"));
}
}
}
private string _selectedPerson;
public string SelectedPerson
{
get { return _selectedPerson; }
set
{
_selectedPerson = …Run Code Online (Sandbox Code Playgroud) 我有一个Person类:
public class Person : INotifyPropertyChanged
{
private string _name;
public string Name{
get { return _name; }
set {
if ( _name != value ) {
_name = value;
OnPropertyChanged( "Name" );
}
}
private Address _primaryAddress;
public Address PrimaryAddress {
get { return _primaryAddress; }
set {
if ( _primaryAddress != value ) {
_primaryAddress = value;
OnPropertyChanged( "PrimaryAddress" );
}
}
//OnPropertyChanged code goes here
}
Run Code Online (Sandbox Code Playgroud)
我有一个Address类:
public class Address : INotifyPropertyChanged
{
private string _streetone;
public …Run Code Online (Sandbox Code Playgroud) 我写了两个应用程序(目标姜饼).让我们说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) 我想有hjkl键来浏览我的面板的目录/文件.这有点像用hjkl elinks,少用hjkl或vifm.
按Ctrl +键左键做一个alt + i
你知道这些关键捷径是否可行?如果是,请你介意给出一些配置文件的帮助或示例.
期待着听到你
亲切的问候
我知道这已被问了一千次,但是我需要选择一个可以将C++函数和方法暴露给python的库.
考虑到我的应用程序,主要是科学(矩阵)库,以及python生成器的成熟度,支持可用性和性能,我遇到了两个选项:
我已经消除了(出于好的或坏的原因)其他选项,如SWIG,SIP,Pybindgen,......
关于那2个图书馆的任何建议?任何具有杀手功能的东西?
我的项目有名称空间,嵌套类,回调等.
谢谢
我正在构建一个按钮样式,它依赖于将颜色画笔转换为较暗的阴影来创建阴影.在常规的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属性更暗的新画笔,因此按钮的阴影总是比它的主背景颜色稍暗.
看到这个简单的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,并且调试器实际上不再能够调用该 …