質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

Q&A

1回答

3276閲覧

[C#][WPF] List ViewにUIElementをアイコン状に表示

yoshida_

総合スコア13

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

WPF

Windows Presentation Foundation (WPF) は、魅力的な外観のユーザー エクスペリエンスを持つ Windows クライアント アプリケーションを作成するための次世代プレゼンテーション システムです

0グッド

1クリップ

投稿2017/04/04 05:54

編集2017/04/04 06:05

WPF(C#)でList ViewにRectangleなどのUIElementをアイコンのように表示させ、選択できるようにしたいのですが、List Viewでそう言った処理は可能でしょうか?
自分なりに調べてみましたが、一覧表示の情報しか見つけられませんでした。

C#側で項目ごとに異なるUIElement(Line, Rectangleなど)を設定できるようにしたいと思っています。

ご教授願います。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答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

hihijiji

総合スコア4150

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問