WPF(C#)でList ViewにRectangleなどのUIElementをアイコンのように表示させ、選択できるようにしたいのですが、List Viewでそう言った処理は可能でしょうか?
自分なりに調べてみましたが、一覧表示の情報しか見つけられませんでした。
C#側で項目ごとに異なるUIElement(Line, Rectangleなど)を設定できるようにしたいと思っています。
ご教授願います。
気になる質問をクリップする
クリップした質問は、後からいつでもMYページで確認できます。
またクリップした質問に回答があった際、通知やメールを受け取ることができます。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。

回答1件
0
こんな感じですか?
XAML
1<Window x:Class="TestWpfApplication.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 5 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 6 xmlns:local="clr-namespace:TestWpfApplication" 7 mc:Ignorable="d" 8 Title="MainWindow" Height="350" Width="525"> 9 <Grid> 10 <ListView ItemsSource="{Binding MyElements}" SelectedItem="{Binding SelectedElement}"> 11 <ListView.ItemTemplate> 12 <DataTemplate> 13 <Border> 14 <ContentPresenter Content="{Binding}"/> 15 </Border> 16 </DataTemplate> 17 </ListView.ItemTemplate> 18 </ListView> 19 </Grid> 20</Window>
C#
1using System.Windows; 2 3namespace TestWpfApplication 4{ 5 /// <summary> 6 /// MainWindow.xaml の相互作用ロジック 7 /// </summary> 8 public partial class MainWindow : Window 9 { 10 public MainWindow() 11 { 12 InitializeComponent(); 13 14 DataContext = new MyViewModel(); 15 } 16 } 17}
C#
1using System.Collections.Generic; 2 3using System.Windows; 4using System.Windows.Shapes; 5using System.Windows.Media; 6 7namespace TestWpfApplication 8{ 9 public class MyModel 10 { 11 public static IList<UIElement> GetElements() 12 { 13 return new UIElement[] 14 { 15 new Rectangle 16 { 17 Stroke = Brushes.Black, 18 Height = 30, 19 Width = 35 20 }, 21 new Line 22 { 23 Stroke = Brushes.Red, 24 X2 = 30, 25 Y2 = 35 26 } 27 }; 28 } 29 30 } 31}
C#
1using System.Collections.Generic; 2using System.Windows; 3 4namespace TestWpfApplication 5{ 6 public class MyViewModel 7 { 8 public IList<UIElement> MyElements => MyModel.GetElements(); 9 10 public UIElement SelectedElement { get; set; } 11 } 12}
投稿2017/04/04 07:56
総合スコア4152
あなたの回答
tips
太字
斜体
打ち消し線
見出し
引用テキストの挿入
コードの挿入
リンクの挿入
リストの挿入
番号リストの挿入
表の挿入
水平線の挿入
プレビュー
質問の解決につながる回答をしましょう。 サンプルコードなど、より具体的な説明があると質問者の理解の助けになります。 また、読む側のことを考えた、分かりやすい文章を心がけましょう。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。