我试过一个代码,我从文件夹中检索视频名称。当我从组合框中选择一些项目时,它不会在组合框选择中显示名称。我通过stackoverflow查看所有内容。但它都没有解决这个问题。请提出任何建议。
代码
public partial class TextToSignWindow : Window
{
public TextToSignWindow()
{
InitializeComponent();
var rootFolder = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
var root = rootFolder + @"\Videos\";
string localPath = new Uri(root).LocalPath;
PopulateListBox(data,localPath, "*.wmv");
}
private void PopulateListBox(ComboBox cmb, string Folder, string FileType)
{
DirectoryInfo dinfo = new DirectoryInfo(Folder);
FileInfo[] Files = dinfo.GetFiles(FileType);
foreach (FileInfo file in Files)
{
var ext = Path.GetExtension(file.Name);
var name = Path.GetFileNameWithoutExtension(file.Name);
cmb.Items.Add(name);
}
}
private void data_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
data.SelectedValue =data.SelectedItem.ToString();
}
}
WPF
<ComboBox x:Name="data"
IsEditable="True"
FontFamily="verdana"
IsSynchronizedWithCurrentItem="True"
FontSize="28"
Text=""
HorizontalAlignment="Left"
Height="81"
Margin="29,214,0,0"
VerticalAlignment="Top"
Width="326"
SelectionChanged="data_SelectionChanged_1"
SelectedItem="{Binding SelectedItem}" />
答案 0 :(得分:0)
您需要包含DisplayMemberPath
CREATE OR REPLACE PACKAGE test_record
AS
TYPE jobs_stat_t IS RECORD (
valid NUMBER,
header_id NUMBER,
child_header_id NUMBER,
order_number NUMBER,
line_number NUMBER,
parent_line_number NUMBER,
wip_entity_id NUMBER,
status_type VARCHAR2 (30),
ordered_item VARCHAR2 (50),
remarks VARCHAR2 (100)
);
TYPE jobs_stat_table_t IS TABLE OF jobs_stat_t
INDEX BY BINARY_INTEGER;
PROCEDURE get_jobs_stat (
p_jobs_stat_table IN jobs_stat_table_t
);
END test_record;
您可能还需要包含SelectedValuePath =“NameOfSelectedValueField”
例如:通常,DisplayMemberPath是您的描述字符串,而SelectedValuePath是您的Id int。
以下是我目前正在使用的代码的复制粘贴:
<ComboBox x:Name="data" IsEditable="True" FontFamily="verdana" IsSynchronizedWithCurrentItem="True" FontSize="28" Text="" HorizontalAlignment="Left" Height="81" Margin="29,214,0,0" VerticalAlignment="Top" Width="326" SelectionChanged="data_SelectionChanged_1" SelectedItem="{Binding SelectedItem}" DisplayMemberPath="NameOfFieldToDisplay"/>
答案 1 :(得分:0)
我尝试了一个样本吗?
的Xaml
<ComboBox x:Name="data" IsEditable="True" FontFamily="verdana" IsSynchronizedWithCurrentItem="True" FontSize="28" Text="" HorizontalAlignment="Left" Height="81" Margin="29,214,0,0" VerticalAlignment="Top" Width="326" SelectionChanged="data_SelectionChanged_1" />
背后的代码
private void Window_Loaded(object sender, RoutedEventArgs e)
{
data.Items.Add("test");
data.Items.Add("test1");
}
private void data_SelectionChanged_1(object sender, SelectionChangedEventArgs e)
{
data.SelectedValue = data.SelectedItem.ToString();
}
答案 2 :(得分:0)
不要将你的组合框发送到功能
<style>
#getFixed{
width: 100%;
height: 60px;
background: green;
display: none;
z-index: 999;
}
</style>
如果你想发送,请参考ref
private void PopulateListBox(string Folder, string FileType)
{
DirectoryInfo dinfo = new DirectoryInfo(Folder);
FileInfo[] Files = dinfo.GetFiles(FileType);
foreach (FileInfo file in Files)
{
var ext = Path.GetExtension(file.Name);
var name = Path.GetFileNameWithoutExtension(file.Name);
data.Items.Add(name);
}
}