wpf 및 xaml (일반적으로 Windows 개발)에 익숙하지 않으며 내 배경은 asp.net이고 이전 asp는 이전입니다. 처리가 발생하는 동안 비활성화 된/회색으로 표시된 단추가 있어야하는 응용 프로그램에서 작업 중이며 여기에서 게시물을 읽으면 다음 작업을 수행 할 수 있지만 작동하지 않는 것으로 보입니다. 누군가 내가 놓친 걸 도와 주시겠습니까?요청 처리 중 버튼 사용 안 함
private bool _isEnabled = true;
public bool IsEnabled
{
get { return _isEnabled; }
set { _isEnabled = value; }
}
과 : 나는 다음이 뷰 모델에서
<Button Content="Execute Weather Import" Command="{Binding ExecuteWeather}" Style="{StaticResource ButtonStyle}" IsEnabled="{Binding IsEnabled}"/>
:
<Window x:Class="SCGen.Application.LoadForecast.EngineExecution"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:igEditors="http://infragistics.com/Editors"
SizeToContent="WidthAndHeight"
Title="Engine Execution"
ResizeMode="NoResize"
WindowStartupLocation="CenterOwner"
Background="{StaticResource {x:Static SystemColors.ControlBrushKey}}">
<Window.Resources>
<Style TargetType="{x:Type Button}" x:Key="myStyle" BasedOn="{StaticResource ButtonStyle}">
<Setter Property="Command" Value="{Binding ExecuteEngine}" />
<Setter Property="Content" Value="Execute Engine" />
<Style.Triggers>
<Trigger Property="Command" Value="{x:Null}">
<Setter Property="IsEnabled" Value="False"/>
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
<Border Padding="8">
<StackPanel>
<StackPanel MaxWidth="200" HorizontalAlignment="Left">
<TextBlock Text="Select Forecast Engine" TextAlignment="Center" FontSize="13" />
<igEditors:XamComboEditor ItemsSource="{Binding ForecastEngines}" SelectedItem="{Binding SelectedEngine}" Margin="0,5" />
<Button Style="{StaticResource ResourceKey=myStyle}" />
</StackPanel>
<TextBlock Text="{Binding EngineStatus}" FontSize="15" FontStyle="Italic" Margin="0,14" Width="400" TextWrapping="Wrap" />
</StackPanel>
</Border>
는
내가 다음에 XAML을 변경했습니다 감사 _isEnabl을 설정했습니다. 여기에 :
private string LaunchWeatherImport(string strVendor)
{
_isEnabled = false;
string uri = ConfigurationManager.AppSettings["ManualExecutionFacilitatorService"];
ClientConnectionInfo connection = new ClientConnectionInfo(uri) { UseSecurity = true };
connection.SetTimeouts();
Logger.LogInfo("Calling Facilitator service to manually import " + strVendor + " weather data.");
((NetTcpBinding)connection.Binding).Security.Mode = System.ServiceModel.SecurityMode.None;
using (var client = new FacilitatorManualExecutionClient(connection))
{
client.InnerChannel.OperationTimeout = TimeSpan.FromMinutes(int.Parse(ConfigurationManager.AppSettings["OperationTimeOutMinutes"]));
try
{
_isEnabled = true;
return "success";
// uncomment this line before commit
//return client.ExecuteWeather(strVendor);
}
#region catch
catch (Exception ex)
{
Logger.LogError(ex.Message, ex);
return ex.Message;
}
#endregion
}
}
나는 여전히 제대로 작동하지 않을 수 있습니다. 이것에 추가해야하는 것에 대해 유감스럽게 생각하지만 댓글의 답장 필드는 코드를 게시 할만큼 길지 않습니다. 우선 들어
나는 질문은 이미 대답 추측,하지만 난 '때 점을 지적하고 싶습니다 \ 커맨드를 사용하면 특정 커맨드와 관련된 컨트롤을 비활성화하기 위해'CanExecute' 메소드를 사용할 수 있습니다. 관심이 있다면 [msdn] (http://msdn.microsoft.com/en-us/library/system.windows.input.routedcommand.canexecute.aspx)에서 몇 가지 정보를 읽을 수 있습니다. – icebat