LoginSignup
0
0

More than 5 years have passed since last update.

Visual Studio / WPF > LINQ > LINQクエリの結果をバインドする(1)

Last updated at Posted at 2017-06-05
動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

http://gushwell.ldblog.jp/archives/52329600.html
を元に学習中。

DataTemplate を使っているが、DataTemplate を使わない状態が気になったので試してみた。

MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace _170605_t1927_linq
{
    /// <summary>
    /// MainWindow.xaml の相互作用ロジック
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            var colorInfos = from color in typeof(Colors).GetProperties()
                             select new
                             {
                                 Name = color.Name,
                                 Color = color.GetValue(null, null)
                             };
            listBox1.ItemsSource = colorInfos;
        }
    }
}

MainWindow.xaml
<Window x:Class="_170605_t1927_linq.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:_170605_t1927_linq"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListBox Margin="15,15,15,45" Name="listBox1"/>
        <Border VerticalAlignment="Bottom"
                BorderThickness="1" BorderBrush="Gray">
            <ContentControl
                Content="{Binding SelectedItem, ElementName=listBox1}"/>
        </Border>
    </Grid>
</Window>

2017-06-05_19h35_48.png

上記の状態に対して、DataTemplate で見栄えを変えているようだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0