1
アイコンをComboBox.ItemTemplateに追加すると、私は奇妙な動作をしています。 最初にアイテムをロードした後、すべてのアイテムに対応するアイコンが表示されますが、アイテムを1つ選択するとアイコンがコンボパートに表示されますが、エクスパンダパートでは表示されなくなります。Mahapps WPF - コンボボックスバインドでの不思議な動作
You can see the problem here (imgur)
私はWPF/C#で経験していないよ、私はアイテムやComboBox.ItemTemplateを結合てる途中に何か問題はありますか? help.-
XAMLコード
<ComboBox x:Name="comboBox" HorizontalAlignment="Left" Height="32" Margin="60,47,0,0" VerticalAlignment="Top" Width="282" ItemsSource="{Binding OtherTasks}" >
<ComboBox.ItemTemplate>
<DataTemplate>
<DockPanel Margin="0" Height="30">
<ContentControl Content="{Binding Path=Icono}" Margin="0,4,0,0" Background="Yellow" Width="16" Height="16" Visibility="Visible"/>
<AccessText HorizontalAlignment="Stretch" Margin="3,4,0,0" Text="{Binding Path=Text}" TextAlignment="Left" Width="Auto" />
</DockPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
CSコード
namespace test___icon {
public partial class MainWindow : MetroWindow {
public class CLASS_OTHERTASKS {
public string Text { get; set; }
public object Icono { get; set; }
}
public List<CLASS_OTHERTASKS> OtherTasks { get; set; }
public MainWindow() {
OtherTasks = new List<CLASS_OTHERTASKS>();
OtherTasks.Add(new CLASS_OTHERTASKS() { Text = "Test Air", Icono = new PackIconEntypo() { Kind = PackIconEntypoKind.Air } });
OtherTasks.Add(new CLASS_OTHERTASKS() { Text = "Test Account", Icono = new PackIconMaterial() { Kind = PackIconMaterialKind.Account } });
OtherTasks.Add(new CLASS_OTHERTASKS() { Text = "Test AxisThree", Icono = new PackIconModern() { Kind = PackIconModernKind.AxisThree } });
InitializeComponent();
this.DataContext = this;
}
}
}
答えていただきありがとうございます。カスタムクラスCLASS_OTHERTASKSとあなたが投稿したDatatriggersにいくつかの修正を加えました。問題を解決できました。 – Capis