System.Windows.Media.Color color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("#4597FF");
btnConfirm.Background = new SolidColorBrush(color);
/// <summary>
/// 从配置文件获取Value
/// </summary>
/// <param name="key">配置文件中key字符串</param>
/// <returns></returns>
public static string GetConfigValue(string key)
{
try
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//获取AppSettings的节点
AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");
return appsection.Settings[key].Value;
}
catch
{
return "";
}
}
/// <summary>
/// 设置配置文件
/// </summary>
/// <param name="key">配置文件中key字符串</param>
/// <param name="value">配置文件中value字符串</param>
/// <returns></returns>
public static bool SetConfigValue(string key, string value)
{
try
{
//打开配置文件
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
//获取AppSettings的节点
AppSettingsSection appsection = (AppSettingsSection)config.GetSection("appSettings");
appsection.Settings[key].Value = value;
config.Save();
return true;
}
catch
{
return false;
}
}
配置文件App.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!--0正式 1测试-->
<add key="IsDebug" value="1" />
</appSettings>
</configuration>
注意
点击事件不要添加在Item的模板中,除非模板中有多个可点击的项。
XAML
<ListBox
x:Name="type_list_lb"
Grid.Column="1"
Background="#f3f3f3"
BorderThickness="0"
ItemContainerStyle="{StaticResource ListBoxItemContainerStyle1}"
ItemTemplate="{StaticResource typeItemDT}"
ItemsSource="{Binding typeList}"
Template="{StaticResource ListBoxTemplateH}"
SelectionChanged="type_list_lb_SelectionChanged"/>
点击事件
private async void type_list_lb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
object sitem = type_list_lb.SelectedItem;
if (sitem == null)
return;
if (sitem is ZListItemModel)
{
ZListItemModel item = (ZListItemModel)sitem;
ObservableCollection<ZListItemModel> typeList = pageData.typeList;
for (int i = 0; i < typeList.Count; i++)
{
ZListItemModel item_temp = typeList[i];
if (item_temp == item)
{
item_temp.selected = 1;
}
else
{
item_temp.selected = 0;
}
}
}
}
如果想让选中的项能够再次点击
设置选中索引即可
type_list_lb.SelectedIndex = -1;
private async Task myFunc()
{
MyApp.Myloading.Show();
await Task.Run(
() =>
{
// 分线程耗时操作
Thread.Sleep(1000);
}
);
MyApp.Myloading.Hide();
}
internal class ZDelayUtil
{
public static void delay(int milliseconds, Dispatcher dispatcher, Action act)
{
Task.Run(() =>
{
Thread.Sleep(milliseconds);
dispatcher.Invoke(act);
});
}
}
调用
ZDelayUtil.delay(
3000,
Dispatcher,
() =>
{
tip_outer.Visibility = Visibility.Hidden;
}
);