AutoCompleteBoxを介して従来のWpf構造を使用しようとしています(ViewModelを使用していません)
私は初めてでWPF
あり、まだ知識を習得していないのでMVVM
..
今のところ私のコード:
PS
このサンプルコードで使用する場合、ソースファイルは-タブで区切られている必要があります。各行は次のようになります。
行番号'(参照用のみ)、タブ区切り、オートコンプリートの値。
- すべての行
- 価値がある
- で区切られています
- タブ="\t"
XAML:
メイン宣言-ウィンドウ
// this happens to be a borderless - window with custom buttons
<Window x:Class="AllDayWpf.MainWindow" Icon="/AllDayWpf;component/bin/Debug/ScheduledTICON.png"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:acb="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input.Toolkit"
xmlns:System="clr-namespace:System;assembly=mscorlib"
Title="Daily Tasks Srv-2" Height="555" Width="731"
ResizeMode="NoResize"
WindowStyle="None"
AllowsTransparency="True" Background="{x:Null}">
<Window.Effect>
<DropShadowEffect Opacity="0.5" BlurRadius="5" ShadowDepth="5" />
</Window.Effect>
TabItem内のグリッド(残りは無関係だと思います):
<Grid>
<ListBox Name="LBX_AddTaskOptions" SelectionChanged="LBX_AddTaskOptions_SelectionChanged" HorizontalAlignment="Left" Margin="19,29,0,0" VerticalAlignment="Top" Width="125" FontWeight="Bold" Background="Beige">
<ListBoxItem Background="#9B6ADBCD" FontWeight="Bold" BorderBrush="#FF27AA27">
<StackPanel Orientation="Horizontal">
<TextBlock Text="internet" Width="74"></TextBlock>
<Image Source="Images\IE_BlackRed.png" Height="30"></Image>
</StackPanel>
</ListBoxItem>
<ListBoxItem Background="#9B6ADBCD" FontWeight="Bold" BorderBrush="#FF27AA27">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Local Folder" Width="74"></TextBlock>
<Image Source="Images\Folder_Black.png" Height="30" Width="32"></Image>
</StackPanel>
</ListBoxItem>
</ListBox>
<acb:AutoCompleteBox Name="UrlACBXml" ValueMemberPath="url" HorizontalAlignment="Left" Grid.Column="1" Width="296" Margin="150,23,0,156" Background="#FFEDF4AB">
<acb:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding url}" FontWeight="Bold" Foreground="Black" Width="30"/>
</StackPanel>
</DataTemplate>
</acb:AutoCompleteBox.ItemTemplate>
</acb:AutoCompleteBox>
</Grid>
ここにautoCompleteboxを配置する必要がありました。
ACB
初期の可視性=非表示。
次に、ユーザーがitem-internetを選択すると、これACB
はVisibleに変わります。
(この段階では実装されていない、単なるアイデアです)
C#オートコンプリートコード。
public MainWindow()
{
InitializeComponent();
MyUrlObsrvblCollcntFactory UrlObsrCollcntFctry= new MyUrlObsrvblCollcntFactory();
UrlACBXml.ItemsSource = UrlObsrCollcntFctry.AutComplObsrvblCllctn;
}
public class MyUrlObsrvblCollcntFactory
{
public class URLsSrcClss
{
public string url { get; set; }
}
String path = System.IO.Path.Combine(Environment.CurrentDirectory,"tst.txt");
string[] testit;
public ObservableCollection<URLsSrcClss> AutComplObsrvblCllctn { get; set; }
public MyUrlObsrvblCollcntFactory()
{
if (File.Exists(path))
{
testit = File.ReadLines(path).ToArray();
foreach (var item in testit)
{
var TabSeparatedItemArr = item.Split('\t');
this.AutComplObsrvblCllctn.Add( new URLsSrcClss { url = TabSeparatedItemArr[1] }
);
}
}
}
}
問題は、オートコンプリートをテストしたときに使用したことです
ObservableCollection<URLsSrcClss> AutComplObsrvblCllctn = new ObservableCollection<URLsSrcClss>
{
new URLsSrcClss {url = "say yhoo..."},
new URLsSrcClss {url = "...google..."},
};
それはうまくいきました
大規模なデータソースから生成されるコードを変更することは、機能を損なうものだと思いますが。それは少なくとも今のところ私が思うことです。
私のコードの何が問題になっていますか?