ui: Use converter to generate 'pretty name' for sec criteria clause
This commit is contained in:
1 parent
948b23addc
commit
7f349cfa71
3 files changed
+76
-1
No files matched your search
@@ -0,0 +1,28 @@
|
||||
namespace mbts.ui.converters {
|
||||
using mbts.spark;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
|
||||
class SecurityCriteriaClauseTextConverter : IMultiValueConverter {
|
||||
public static SecurityCriteriaClauseTextConverter Instance => new();
|
||||
|
||||
public object Convert(
|
||||
object[] values, Type target_type, object parameter, CultureInfo culture) {
|
||||
if (!ConvertUtils.try_convert_args(
|
||||
values,
|
||||
out SecurityCriteriaClause clause,
|
||||
out IReadOnlyDictionary<uint, SecurityMD> sec_md_map)) {
|
||||
return null;
|
||||
}
|
||||
return clause.pretty_name ?? clause.fmt_pretty(
|
||||
id => sec_md_map.TryGetValue(id, out var smd) ? smd.security.Symbol : string.Empty);
|
||||
}
|
||||
|
||||
public object[] ConvertBack(
|
||||
object value, Type[] target_types, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace mbts.ui.converters {
|
||||
using bts.utils;
|
||||
|
||||
using mbts.spark;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows.Data;
|
||||
|
||||
class SecurityCriteriaTextConverter : IMultiValueConverter {
|
||||
public static SecurityCriteriaTextConverter Instance => new();
|
||||
|
||||
public object Convert(
|
||||
object[] values, Type target_type, object parameter, CultureInfo culture) {
|
||||
if (!ConvertUtils.try_convert_args(
|
||||
values,
|
||||
out SecurityCriteria criteria,
|
||||
out IReadOnlyDictionary<uint, SecurityMD> sec_md_map)) {
|
||||
return null;
|
||||
}
|
||||
return $" {SpecialCharacters.DotChar} ".join(
|
||||
criteria.clauses.Select(
|
||||
c => c.pretty_name ?? c.fmt_pretty(
|
||||
id => sec_md_map.TryGetValue(id, out var smd) ?
|
||||
smd.security.Symbol : string.Empty)));
|
||||
}
|
||||
|
||||
public object[] ConvertBack(
|
||||
object value, Type[] target_types, object parameter, CultureInfo culture) =>
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -352,7 +352,6 @@
|
||||
Visibility="{Binding is_edit_mode, Converter={StaticResource BoolToVisibility}}"
|
||||
SelectionMode="Extended"
|
||||
SelectedValuePath="value"
|
||||
DisplayMemberPath="value"
|
||||
Margin="12,0,0,10"
|
||||
VerticalAlignment="Stretch"
|
||||
Height="90">
|
||||
@@ -372,6 +371,20 @@
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ListBox.ItemContainerStyle>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock>
|
||||
<TextBlock.Text>
|
||||
<MultiBinding Converter="{x:Static cv:SecurityCriteriaClauseTextConverter.Instance}">
|
||||
<Binding Path="value" />
|
||||
<Binding
|
||||
Path="DataContext.all_security_mds"
|
||||
RelativeSource="{RelativeSource AncestorType=sp:ContractPickerView}" />
|
||||
</MultiBinding>
|
||||
</TextBlock.Text>
|
||||
</TextBlock>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<Button
|
||||
Grid.Row="1"
|
||||
|
||||
Reference in new issue
Block a user