我有两个独立的可见性转换器,一个基于字段是否已更新,另一个基于是否允许查看字段.我对我页面上的每个文本项使用updatedField,以便在更新的字段旁边显示一个星号.但是某些用户只能根据权限级别看到某些文本项.
例如:
<Image Visibility="{Binding ElementName=MyObject, Path=UpdatedFields, Mode=OneWay, Converter={StaticResource updatedFieldConverter}, ConverterParameter=FieldToTest}" Source="Properties:Resources.star_yellow" />
Run Code Online (Sandbox Code Playgroud)
和
<TextBlock FontSize="21" Foreground="{DynamicResource LabelBrush}" Text="{x:Static Properties:Resources.Some_Text}" Visibility="{Binding Source={StaticResource allowedFields}, Path=Some_Text_Field, Converter={StaticResource visibilityConverter}}" />
Run Code Online (Sandbox Code Playgroud)
我的问题是,对于需要许可的字段,我需要运行两个转换器来确定星是否出现.有没有办法在两个转换器的结果上做一个布尔"And"?
我查看了这篇文章,但它似乎不允许将不同的参数集传递给两个不同的转换器.
------- --------更新
我还试图用这个xaml创建一个MultiValueConverter
<Image Grid.Row="4" Grid.Column="0" Source="star_yellow.png">
<Image.Visibility>
<MultiBinding Converter="{StaticResource combinedVisibilityConverter}" ConverterParameter="FieldToTest" >
<Binding ElementName="allowedFieldsModel" Path="Some_Text_Field" Mode="OneWay" />
<Binding ElementName="MyObject" Path="UpdatedFields" Mode="OneWay" />
</MultiBinding>
</Image.Visibility>
</Image>
Run Code Online (Sandbox Code Playgroud)
但是当它进入转换器时,两个值都是"DependencyProperty.UnsetValue".所以我显然在这里做错了.
- - - - 解 - - - - -
我不得不修改它,但后来它工作了.
<Image.Visibility>
<MultiBinding Converter="{StaticResource combinedVisibilityConverter}" ConverterParameter="FieldToTest">
<Binding Source="{StaticResource allowedFieldsModel}" Path="Some_Text_Field" />
<Binding Path="MyObject.UpdatedFields" …
Run Code Online (Sandbox Code Playgroud) 我有点困惑.我无法在任何地方找到答案;(
我有一个String数组:
String[] arr = ["1", "2", "3"];
Run Code Online (Sandbox Code Playgroud)
然后我将它转换为字符串:
String str = Arrays.toString(arr);
System.out.println(str);
Run Code Online (Sandbox Code Playgroud)
我期望得到字符串"123"
,但我得到了字符串"[1,2,3]"
.
我怎么能在java中做到这一点?我正在使用Eclipse IDE
我正在寻找一种将XML-Object转换为字符串的方法.
有没有像Powershell中的$ xml.toString()?
我需要找到一个好的Lua到JavaScript转换器; luaforj.org上的lua2js已经过时(大约3年左右,看起来它不适用于Lua 5.1),我还没有在Google上找到任何东西.
有没有人有任何其他转换器的经验?它应该适用于Lua 5.1,最好是基于.NET的,但.NET不是必需的.一个javascript lua解释器也可以工作.
我有一个组合框,它绑定到数据表列,如下所示:
ComboBox.DataContext = DataDataTable;
ComboBox.DisplayMemberPath = DataDataTable.Columns["IDNr"].ToString();
Run Code Online (Sandbox Code Playgroud)
列中的IDNr始终以4个字母开头,后跟ID号(例如BLXF1234).我需要在没有字母的情况下在Combobox中显示项目(我需要在组合框中显示1234).
所以我写了一个转换器:
class IDPrefixValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null)
{
string s = value.ToString();
if (s.Contains("BL"))
{
return s.Substring(4);
}
else
{
return s;
}
}
return "";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotSupportedException();
}
Run Code Online (Sandbox Code Playgroud)
不,我怎么能告诉组合框使用转换器来显示项目?我在Xaml中试过这个:
ItemsSource="{Binding}"
DisplayMemberPath="{Binding Converter={StaticResource IDPrefixValueConverter}}"
Run Code Online (Sandbox Code Playgroud)
但仍然没有工作...任何想法?谢谢
我怎么可以注入的依赖一样@EJB
,@PersistenceContext
,@Inject
,@AutoWired
,等的@FacesConverter
?在我的具体情况下,我需要通过@EJB
以下方式注入EJB :
@FacesConverter
public class MyConverter implements Converter {
@EJB
protected MyService myService;
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
// myService.doSomething
}
}
Run Code Online (Sandbox Code Playgroud)
然而,它没有被注射并且仍然存在null
,导致NPE.看来,@PersistenceContext
和@Inject
也不起作用.
如何在转换器中注入服务依赖项以便我可以访问数据库?
我正在研究WPF应用程序.我已将文本块绑定到我的按钮.当关联按钮的isEnabled为true时,我想将文本块的前景设置为黑色.我想用转换器做这个.但它不起作用.也没有给出任何错误.我在"Models"文件夹中声明了以下类.
public class BrushColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((bool)value)
{
{
return System.Windows.Media.Colors.Black;
}
}
return System.Windows.Media.Colors.LightGreen;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
Run Code Online (Sandbox Code Playgroud)
Button的启用,可从viewmodel更改属性(例如使用RaiseCanExecuteChanged)())
XAML中与textblock相关的东西是:
<Window.Resources>
<local:BrushColorConverter x:Key="BConverter"></local:BrushColorConverter>
</Window.Resources>
<Button>(!..all button properties..!)</Button>
<TextBlock x:Name="AnswerText"
Text="Answer"
Foreground="{Binding ElementName=AnswerButton,Path=IsEnabled, Converter={StaticResource BConverter}}"
TextWrapping="Wrap"/>
Run Code Online (Sandbox Code Playgroud) 我有一个对象,它有一个DateTime属性...我想通过AJAX/JSON将该对象从.ashx处理程序传递回网页...我不想使用第三方控件...
当我这样做:
new JavaScriptSerializer().Serialize(DateTime.Now);
Run Code Online (Sandbox Code Playgroud)
我明白了:
"\/Date(1251385232334)\/"
Run Code Online (Sandbox Code Playgroud)
但我想要"8/26/2009"(没关系本地化......我的应用程序是非常本地化的,所以我的日期格式化假设在这个问题中没有争议).如果我制作/注册自定义转换器
public class DateTimeConverter : JavaScriptConverter
{
public override IEnumerable<Type> SupportedTypes
{
get { return new List<Type>() { typeof(DateTime), typeof(DateTime?) }; }
}
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
Dictionary<string, object> result = new Dictionary<string, object>();
if (obj == null) return result;
result["DateTime"] = ((DateTime)obj).ToShortDateString();
return result;
}
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
{
if (dictionary.ContainsKey("DateTime"))
return new DateTime(long.Parse(dictionary["DateTime"].ToString()), DateTimeKind.Unspecified);
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我得到这个结果(因为自定义序列化方法的返回值是一个字典):
{"DateTime":"8/27/2009"} …
Run Code Online (Sandbox Code Playgroud) public static T Convert<T>(String value)
{
return (T)Convert.ChangeType(value, typeof(T));
}
public enum Category
{
Empty,
Name,
City,
Country
}
Category cat=Convert<Category>("1");//Name=1
Run Code Online (Sandbox Code Playgroud)
当我调用时Convert.ChangeType
,系统会因无法从String转换为Category而抛出异常.怎么做转换?也许我需要为我的类型实现任何转换器?
我有关于格式化卢比货币(印度卢比 - 印度卢比)的问题.
例如,此处的数字表示为:
1
10
100
1,000
10,000
1,00,000
10,00,000
1,00,00,000
10,00,00,000
Run Code Online (Sandbox Code Playgroud)
参考印度编号系统
我必须用它做PHP.
我看到了这个问题以印度编号格式显示货币.但无法为PHP获取它我的问题.
如何使用印度货币格式的money_format()?
converter ×10
c# ×3
wpf ×3
javascript ×2
string ×2
xaml ×2
.net ×1
ajax ×1
arrays ×1
currency ×1
data-binding ×1
ejb ×1
enums ×1
interpreter ×1
java ×1
jsf ×1
lua ×1
money-format ×1
php ×1
powershell ×1
xml ×1