• 締切済み

Visualbasic2010 WPF データ更新

VisualBasic 2010 を利用してWindowsアプリケーションを行っております。 Form上にElementHostを配置し、データベースより抽出した結果をWPFで作成したグリッド(DataGrid)に表示しております。 以下の点について分る方がいらっしゃいましたらご教授頂けますと幸いです。 DataGridでデータを更新した場合にDataTableも更新したい ソースは以下の構成となります。 ★Item_Main.xaml <UserControl x:Name="UserControl1" x:Class="Item_Main" xmlns:local="clr-namespace:TEST" mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="300" Height="Auto" Width="Auto" GotFocus="UserControl_GotFocus"> <DataGrid x:Name="DataGrid_1" ItemsSource="{Binding}" ScrollViewer.CanContentScroll="True" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Standard" ScrollViewer.IsDeferredScrollingEnabled="True" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility="None" Margin="0,0,0,0"> <DataGrid.Columns> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <local:Item_Detail /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> </UserControl> ★Item_Detail.xaml <UserControl x:Name="UserControl2" x:Class="Item_Detail" mc:Ignorable="d" d:DesignHeight="136" Width="1090" Loaded="UserControl_Loaded"> <UserControl.Background> <SolidColorBrush Color="{DynamicResource {x:Static SystemColors.WindowColorKey}}"/> </UserControl.Background> <Grid Name="GP_Panel" KeyboardNavigation.TabNavigation="Local"> <Grid.ColumnDefinitions> <ColumnDefinition Width="69*"/> <ColumnDefinition Width="151*"/> </Grid.ColumnDefinitions> <TextBox x:Name="Text_Pre_CS" Text="{Binding 数量, Mode=TwoWay, TargetNullValue=0}" HorizontalAlignment="Left" Height="22" Margin="161,102,0,12" TextWrapping="Wrap" Width="60" Background="White" FontFamily="Arial" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" FontWeight="Bold" Foreground="Black" Grid.Column="1" TabIndex="1" FontSize="15" /> </Grid> </UserControl> ★Item_Detail.xaml.vb  ※現在はデータ編集時に以下のように処理しております。 '/ 本画面のDataRowを取得 Dim dt_row As DataRow Dim dt_row_view As DataRowView dt_row_view = CType(Me.DataContext, DataRowView) dt_row = dt_row_view.Row   dt_row.Item("数量") = "0" DataRowはDataTableとは異なると認識しておりますので   現在のロジックではDataTable側は更新されない事は   理解しているのですが、Item_Detail.xaml.vbにて   DataTableの特定行数を取得する方法等が分らず   目的の動作が実現できていません。   大変お手数おかけ致しますが、   宜しくお願い致します。 以上です。   

みんなの回答

  • dell_OK
  • ベストアンサー率13% (742/5653)
回答No.2

バインドがあるのだからそれで反映させるのが一番の方法だとは思いますし、そのためのバインドでもあると思います。 「※現在はデータ編集時~」とはどのイベントでしょうか。 そのタイミングで他のコントロールが参照できるのでしたら、DataTableに行番号を持たせておいて、それ用のTextBoxやLabelにバインドしておけば、その行番号を取得できそうな気もします。 そうしておいてDataTableから一致する行を検索して、その行を対象に処理する、かな。 Item_Detail側で現在行を取得するのは無理か難しいので、やるとしたら、DataGridのItem_Main側になると思います。 まず、DataGridに「SourceUpdated」イベントを追加します。 その内容はこんな感じです。 Dim grid = CType(sender, System.Windows.Controls.DataGrid) Dim ci = CType(grid.CurrentItem, DataRowView) Dim row = ci.Row row.Item("数量") = 0 次にItem_DetailのテキストボックスのBindingに以下を追加します。  ,NotifyOnSourceUpdated=True,UpdateSourceTrigger=LostFocus CurrentItemが現在の行の情報なので、そのRowに対して何かすればいいのですが、単純に「0」と言う固定値にすることは簡単にできても、ここからではItem_Detailのテキストボックスを簡単に参照できません。 更新イベントを参考にしたのはこちらです。 https://araramistudio.jimdo.com/2019/09/27/c-%E3%81%AEwpf%E3%81%A7datagrid%E3%81%AE%E5%80%A4%E3%81%8C%E6%9B%B4%E6%96%B0%E3%81%95%E3%82%8C%E3%81%9F%E6%99%82%E3%81%AE%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88/ ひとまず、WIndowsFormからいったんはなれて、WPFだけでデザインやプロパティは最低限にして試してみてはどうでしょうか。 私の方ではどちらで試してもバインドで反映されてしまうので、質問者さまと同じ状況でのテストができていません。

全文を見る
すると、全ての回答が全文表示されます。
  • dell_OK
  • ベストアンサー率13% (742/5653)
回答No.1

テキストボックスのバインディングに 「,UpdateSourceTrigger=PropertyChanged」 を追加して、試してみてください。 <TextBox x:Name="Text_Pre_CS" Text="{Binding 数量, Mode=TwoWay, TargetNullValue=0,UpdateSourceTrigger=PropertyChanged}" 「PropertyChanged」はテキストボックスに文字を入力する都度反映されるのであまりいいタイミングではありません。例えば「100」と入力するとして、最初の「1」次の「0」さらに次の「0」で計3回データテーブルへの反映が発生します。 他には「LostFocus」があり、文字を入力する都度ではないものの、フォーカスが外れないと反映されないので、最後の入力決定のタイミングが他のコントロールに移動する必要があるのですが、WindowsForm側のボタンを押すとかでも大丈夫です。 もうひとつ「Explicit」と言うのがあるのですが、難しそうだったので試していません。

19820202
質問者

補足

ご教授頂きましてありがとうございます。 早速「UpdateSourceTrigger=PropertyChanged」を組み込んで検証してみたのですが、DataTableには反映しないようでした。 Item_Detail側でDataTableのカレント行番号が取得できれば処理できるのではないかと考えているのですが、そのような方法は難しいのでしょうか。

全文を見る
すると、全ての回答が全文表示されます。

関連するQ&A

  • VisualBasic 2010 WPFのData

    Visualbasic 2010を利用してWindows Formアプリケーションに WPFのDataGridを配置しております。 以下の2点の制御を行いたいと考えておりますが、 ご存知の方がいらっしゃればご教授頂けますと幸いです。 (1)フォームよりWPFのDataDrid内の値を編集した場合に  Dattableに反映したい  現在はフォーム側で以下のように参照しています。 Dim dt_row As DataRow Dim dt_row_view As DataRowView   dt_row_view = CType(Me.DataContext, DataRowView) dt_row = dt_row_view.Row (2)DataGridにTextBoxを2つ配置(数量1、数量2)しておりますが、  エンターキー押下時に数量1、数量2の順でカーソル遷移でき  ないでしょうか。  現在はエンターキーを押下すると次の行に遷移してしま  います。 以下にソースの抜粋を掲示致します。 ★Form1.vb (HostedContentName) Item_Main2 Me.Item_Main2.DataContext = dt   ※データテーブルにはDBからSELECTした結果をセットしています。 ★Item_Main.xaml <UserControl x:Name="UserControl1" x:Class="Item_Main" xmlns:local="clr-namespace:TESTアプリ" <DataGrid x:Name="DataGrid_1" ItemsSource="{Binding}" ScrollViewer.CanContentScroll="True" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Standard" ScrollViewer.IsDeferredScrollingEnabled="True" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility="None" Margin="0,0,0,0" KeyDown="DataGrid_KeyDown"> <DataGrid.Columns> <DataGridTemplateColumn> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <local:Item_Detail /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> </ ★Item_Detail.xaml.vb Private Sub Btn_Click(sender As Object, e As Windows.RoutedEventArgs) Handles Btn.Click Dim dt_row As DataRow Dim dt_row_view As DataRowView dim wk_1 as string '/ 本画面のDataRowを取得 dt_row_view = CType(Me.DataContext, DataRowView) dt_row = dt_row_view.Row '/ 画面で編集した値を変数にセット If COMMON.NullNothingChk(dt_row.Item("数量1")) = False Then wk_1 = dt_row.Item("数量1").ToString Else wk_1 = "0" End If '/ 画面で編集した内容をデータテーブルにセットしたい '/ 今のままではグリッドを再描画すると編集内容がクリアされてしまう End Sub ★Item_Detail.xaml <UserControl x:Name="UserControl2" x:Class="Item_Detail" mc:Ignorable="d" d:DesignHeight="136" Width="1090" Loaded="UserControl_Loaded"> <Grid Name="GP_Panel" KeyboardNavigation.TabNavigation="Local"> <Grid.ColumnDefinitions> <ColumnDefinition Width="69*"/> <ColumnDefinition Width="151*"/> </Grid.ColumnDefinitions> <TextBox x:Name="Text_ItemCd" Text="{Binding 商品コード}" HorizontalAlignment="Left" Height="20" TextWrapping="Wrap" Width="56" Background="{x:Null}" FontFamily="Arial" FontSize="14" VerticalContentAlignment="Center" FontWeight="Bold" IsHitTestVisible="True" Foreground="Black" Margin="4,23,0,93" HorizontalContentAlignment="Center" IsReadOnly="True" IsTabStop="False"/> <TextBox x:Name="Text_ItemNm" Text="{Binding 商品名}" HorizontalAlignment="Left" Height="20" TextWrapping="Wrap" Width="316" Background="{x:Null}" FontFamily="Arial" FontSize="16" VerticalContentAlignment="Center" IsHitTestVisible="True" Foreground="Black" Margin="62,23,0,93" BorderBrush="{x:Null}" Grid.ColumnSpan="2" IsReadOnly="True" IsTabStop="False"/> <TextBox x:Name="Text_1" Text="{Binding 数量1, Mode=TwoWay, TargetNullValue=0}" HorizontalAlignment="Left" Height="18" Margin="176,102,0,16" TextWrapping="Wrap" Width="60" Background="White" FontFamily="Arial" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" FontWeight="Medium" Foreground="Black" Grid.Column="1" TabIndex="1" /> <TextBox x:Name="Text_2" Text="{Binding 数量2, Mode=TwoWay, TargetNullValue=0}" HorizontalAlignment="Left" Height="18" Margin="236,102,0,16" TextWrapping="Wrap" Width="60" Background="White" FontFamily="Arial" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" FontWeight="Medium" Foreground="Black" Grid.Column="1" TabIndex="2" /> </Grid> </UserControl>

  • WPFのDatagridの縦スクロール

    VisualBasic2010を利用してWindows Formアプリケーションを 開発しております。 その際にForm上にElementHostを配置しWPFで構築した DataGridを設定しグリッドにデータを表示しております。 データ表示自体は問題なく行えているのですが、 Datagridの縦スクロールをWindows Form上に配置する ボタンから制御したいと考えております。 このような制御の方法をご存知の方がいらっしゃいましたら ご教授頂けますと幸いです。 WPF側 <UserControl x:Class="Grid_Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:_01_AAAA" mc:Ignorable="d" d:DesignHeight="200.373" d:DesignWidth="300" Height="Auto" Width="Auto"> <DataGrid ItemsSource="{Binding}" ScrollViewer.CanContentScroll="True" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" ScrollViewer.IsDeferredScrollingEnabled="True" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility="None" Margin="0,0,0,0" BorderBrush="{x:Null}"> <DataGrid.Columns> <DataGridTemplateColumn > <!-- 表示時のセルのテンプレートを指定 --> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <!-- 表示時のセルのテンプレートに同プロジェクト内のクラスを指定 --> <local:Grid_Detail /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> <!-- 編集時のセルのテンプレートを指定 --> <!-- 表示専用であれば定義不要 --> </DataGrid.Columns> </DataGrid> </UserControl>

  • WPF コントロールの参照

    Visualbasic 2010 を利用してWindows Formアプリケーションを開発しております。 Form上にWPF互換のためElementHostを配置し、その中にUserControlを配置しUserControl内にWPFのDataGridを配置しております。 CellTemplateを利用して1つのセル内に複数のTextBoxを配置しております。 ★Main.xaml 抜粋 <DataGridTemplateColumn > <!-- 表示時のセルのテンプレートを指定 --> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <local:Sien_Detail /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> ★Sien_Detail.xaml 抜粋 <TextBox x:Name="Label_0" Text="4/29(金)" HorizontalAlignment="Left" Margin="65,1,0,-19" TextWrapping="Wrap" Width="57" Background="{x:Null}" FontFamily="Arial" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontWeight="Bold" Foreground="Black" BorderBrush="#FFABADB3" IsReadOnly="True" IsTabStop="False" Height="18" /> <TextBox x:Name="Label_1" Text="4/30(土)" HorizontalAlignment="Left" Margin="127,1,0,-19" TextWrapping="Wrap" Width="57" Background="{x:Null}" FontFamily="Arial" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontWeight="Bold" Foreground="Black" BorderBrush="#FFABADB3" IsReadOnly="True" IsTabStop="False" RenderTransformOrigin="1.061,0.622" /> ★Sien_Detail.xaml.vb エラー箇所 Me.Controls("Label_0").Text = "ああ" そのTextBoxをプログラム側で制御したいと考えております。 Windows Formであれば[Me.Controls("TextBox1")]のようなコーディングで参照できるのですが、上記の場合、「Controlsはメンバーではありません」が表示されてしまいます。 どなたか改善策が分る方がいらっしゃいましたらご教授頂けますと幸いです。 以上です。

  • wpf datagrid メモリリーク

    wpfのdatagridを利用してデータ表示しております。 1レコードを多段構成で表示するため、ユーザーコントロールにdatagridを配置し、グリッド内に各コントロールを配置する方法で実現しております。 チェックボックスも配置しており、スクロール時に初期化される現象が発生したため、仮想化をOFFにしております。 少ないデータ件数であれば問題ないのですが、大量データ(3500件程度)の場合には メモリリークしてしまいます。 DataGridにチェックボックスを配置した場合の実装で、上記の事象を 改善する方法をご存知の方がいらっしゃいましたらご教授頂けると幸いです。 以下2つが実装しているxamlとなります。 ★Grid_Tab_Roke_Main  ユーザーコントロールにDataGridを配置したものとして実装しています。 <UserControl x:Class="Grid_Tab_Roke_Main" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:_XX_WPF商品管理" mc:Ignorable="d" d:DesignHeight="200.373" d:DesignWidth="300" Height="Auto" Width="Auto"> <DataGrid ItemsSource="{Binding}" VirtualizingStackPanel.IsVirtualizing="False" VirtualizingStackPanel.VirtualizationMode="Standard" EnableColumnVirtualization="False" EnableRowVirtualization="False" ScrollViewer.CanContentScroll="True" ScrollViewer.IsDeferredScrollingEnabled="True" AutoGenerateColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" HeadersVisibility="None" Margin="0,0,0,0"> <DataGrid.Columns> <DataGridTemplateColumn > <DataGridTemplateColumn.CellTemplate> <DataTemplate> <local:Grid_Tab_Roke_Detail /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn> </DataGrid.Columns> </DataGrid> </UserControl> ★Grid_Tab_Roke_Detail グリッド内にコントロールを配置しており、データテーブルよりバインドしています。項目は全て数点を抜粋して記載しております。 <UserControl x:Class="Grid_Tab_Roke_Detail" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" Height="70" Width="1227" Background="White" Loaded="UserControl_Loaded"> <Grid> <TextBox x:Name="Text_Roke" Text="{Binding ロケーション名, Mode=OneTime, StringFormat=\{0:N0\}}" HorizontalAlignment="Left" Height="21" Margin="56,22,0,27" TextWrapping="Wrap" VerticalAlignment="Center" Width="181" RenderTransformOrigin="0.406,0.026" Background="{x:Null}" FontFamily="Arial" VerticalContentAlignment="Center" FontWeight="Bold" MaxWidth="200" MinHeight="16" IsHitTestVisible="True" FontSize="16" Foreground="Black"/> <TextBox x:Name="Text_HinCD" Text="{Binding 商品コード, Mode=OneTime, StringFormat=\{0:N0\}}" HorizontalAlignment="Left" Height="21" Margin="242,22,0,27" TextWrapping="Wrap" VerticalAlignment="Center" Width="62" RenderTransformOrigin="0.406,0.026" Background="{x:Null}" FontFamily="Arial" VerticalContentAlignment="Center" FontWeight="Bold" MaxWidth="150" MinHeight="16" IsHitTestVisible="True" FontSize="16" Foreground="Black"/> <CheckBox x:Name="Chk_Sentaku" Content="選択" IsChecked="{Binding IsSelected.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="3,3,0,0" VerticalAlignment="Top" Width="48" Height="65" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked" /> <TextBox x:Name="Text_HinNM" Text="{Binding 商品名, Mode=TwoWay, StringFormat=\{0:N0\}}" HorizontalAlignment="Left" Height="21" Margin="304,22,0,27" TextWrapping="Wrap" VerticalAlignment="Center" Width="330" RenderTransformOrigin="0.406,0.026" Background="{x:Null}" FontFamily="Arial" VerticalContentAlignment="Center" FontWeight="Bold" MaxWidth="350" MinHeight="16" IsHitTestVisible="True" FontSize="16" Foreground="Black"/> </Grid> </UserControl>

  • WPFのチェックボックス

    VisualBasic 2013 でWPFを利用してグリッドを作成しております。 ユーザーコントロールにDataGridを配置し、Grid内にチェックボックスを1つ 配置しています。 データ表示後は1レコードに1つチェックボックスが配置された状態と なります。 データ表示は問題なく行えるのですが、チェックボックスの動作が 想定と異なってしまいます。 ・現在チェックボックスの挙動  複数レコードでチェックボックスのチェックを付けた場合、  画面をスクロールするとチェックが消える。 このような現象が発生する原因と対策がお分かりの方がいらっしゃいましたら ご教授頂けると幸いです。 上記現象が発生するxamlは以下の通りです。 <UserControl x:Class="Grid_Tab_Roke_Detail" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" Height="70" Width="1227" Background="White"> <UserControl.Resources> <!-- ラジオボタンの共通styleを指定 --> <!-- トグルボタン風に押すと色を変える --> <Style TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type ToggleButton} }"> <Style.Triggers> <!-- 未チェック時は透明 --> <Trigger Property="IsChecked" Value="{x:Null}"> <Setter Property="Background" Value="Transparent" /> </Trigger> <Trigger Property="IsChecked" Value="False"> <Setter Property="Background" Value="Transparent" /> </Trigger> <!-- チェック時は青 --> <Trigger Property="IsChecked" Value="True"> <Setter Property="Background" Value="Blue"/> </Trigger> </Style.Triggers> </Style> </UserControl.Resources> <Grid> <CheckBox Content="選択" IsChecked="{Binding IsSelected.Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" Margin="3,3,0,0" VerticalAlignment="Top" Width="48" Height="57" /> <TextBox x:Name="Text_HinNM" Text="{Binding 商品名, Mode=OneTime, StringFormat=\{0:N0\}}" HorizontalAlignment="Left" Height="21" Margin="304,22,0,27" TextWrapping="Wrap" VerticalAlignment="Center" Width="330" RenderTransformOrigin="0.406,0.026" Background="{x:Null}" FontFamily="Arial" VerticalContentAlignment="Center" FontWeight="Bold" MaxWidth="350" MinHeight="16" IsHitTestVisible="True" FontSize="16"> <TextBox.Foreground> <SolidColorBrush Color="Black"/> </TextBox.Foreground> </TextBox> </Grid> </UserControl>

  • ルート要素に指定しているxmlnsについて教えて下さい。

    「Visual Studio 2008」の評価版を使用しています。 下記の記述はプロジェクトを作成した時に作成されたXAMLファイルです。 ※デフォルトです。 <UserControl x:Class="_sample.Page"  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  Width="400" Height="300">  <Grid x:Name="LayoutRoot" Background="White">  </Grid> </UserControl> 「xmlns」と「xmlns:x」について教えて下さい。 「xmlns」・・・ XML名前空間 「xmlns:x」・・・ XAML言語の名前空間 下記のサイトに書いてありましたが・・・ http://msdn.microsoft.com/ja-jp/library/cc189036(VS.95).aspx#whatisxaml 私が知りたいのはこの「xmlns」と「xmlns:x」の属性は固定ですか。 ※固定というのはURLではありません。 くだらない質問かも知れませんがご教授、お願いします。 失礼します。

  • DataContextについて

    visual C# 2010 Express を使用しています。 UserControl1とUserControl2をFooクラスのメンバAuthorizedによって 切り替えるということをしたいと思い、 MainWindow.xamlの内容を次のようにしました。 <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" xmlns:my="clr-namespace:WpfApplication1"> <Window.DataContext> <my:Foo/> </Window.DataContext> <Grid> <my:UserControl1 HorizontalAlignment="Left" Margin="140,74,0,0" x:Name="userControl11" VerticalAlignment="Top" Height="44" Width="82" Visibility="{Binding Path=NotAuthorized, Converter={StaticResource BooleanToVisibilityConverter1}}" /> <my:UserControl2 Height="45" HorizontalAlignment="Left" Margin="288,65,0,0" x:Name="userControl21" VerticalAlignment="Top" Width="77" Visibility="{Binding Path=Authorized, Converter={StaticResource BooleanToVisibilityConverter1}}" /> <Button Content="Button" Height="38" HorizontalAlignment="Left" Margin="38,109,0,0" Name="button1" VerticalAlignment="Top" Width="80" Click="button1_Click" /> <TextBox Height="40" HorizontalAlignment="Left" Margin="46,34,0,0" Name="textBox1" VerticalAlignment="Top" Width="88" /> </Grid> </Window> そしてFooクラス [Foo.cs] class Foo { private bool _authorized = false; public bool Authorized { get { return _authorized; } set { _authorized = value; } } public bool NotAuthorized { get { return !Authorized; } } } そして、MainWindow.xaml.csのbutton1_Click内で、 Foo f = new Foo(); f.Authorized = true; とやったのですが、切り替わらないのです。 なんとなく自分でもこれだけでは切り替わらないだろうなと想像はつくのですが、 でも下の図のプロパティでは [ソース: (Datacontext - Foo)] とありDatacontextはFooクラスだと認識してますよね? なのでこの記述 Visibility="{Binding Path=NotAuthorized, Converter={StaticResource BooleanToVisibilityConverter1}}" だけでも認識してくれるのかなと期待したのですが、駄目でした・・・ この場合はどう記述すれば良いのでしょうか?またなぜそれが必要なのかという理由も教えて頂けないでしょうか?

  • WPF ブラウザアプリケーション開発について

    いつもお世話になっております。 環境 VS 2008 VISTA SP1 home basic 質問 WPF ブラウザアプリケーションで プロジェクトを立ち上げて 適当にxmalで <Page x:Class="WPFBROWSER.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1"> <Grid> <WrapPanel> <TextBox Width = "100" FontSize = "30" Text = "text 1" Background = "White" Foreground = "Blue" /> <TextBox Width = "100" FontSize = "30" Text = "text 2" Background = "White" Foreground = "Green" /> </WrapPanel> </Grid> </Page> と書いてビルドしたら(ビルドは問題なく通ります) /bin/release/*.exe が作られたのですが このexeをたたいても何も起こりません。 そもそも使い方を間違っている様な気がするのですが・・ このWPF ブラウザアプリケーション でプロジェクトを作った際に どのように役立つ(どのように何かを作っていくのか) のか 情報を探しているのですが よくわかりません。 以上 よろしくお願いします。

  • C#で型変換

    DataTable T_DATATABLE = new DataTable(); DataRow[] T_DATATABLE_row; DataAdapter adp = new DataAdapter("SELECT id,Date FROM TABLE", CONN); adp.Fill(T_DATATABLE); //データテーブルにidとDateフィールドがあります。 //dtに下記で取得したダータを入れようと思っているのですが、 //System.Datetimeに変換することはできませんと表示されます。 DateTime dt = T_DATATABLE.Rows[0]["Date"]; どのようにすれば、型変換をすることができるでしょうか? string dt = (string)T_DATATABLE.Rows[0]["Date"]; string dt = (string)T_DATATABLE.Rows[0]["Date"].toString; としてもできません・・・ ご教授お願い致します!

  • Gridに日付を入れるとき

    Gridに「2006/05/10 13:00:00」と表示させたいのですが、「2006/05/10」と表示されてしまいます。 ------------------------------------------------ Dim dt As DataTable Dim dtSet As New DataSet dt = dtSet.Tables.Add("aaa") dt.Columns.Add("日付", Type.GetType("System.DateTime")) dt.Rows.Add(New Object() {"2006/05/10 14:00:00"}) DataGrid1.DataSource = dt ------------------------------------------------ ソースが間違っているのでしょうか。どなたかアドバイスをお願いします。