WPF TabControl Binding issue
I have TabControl
with two tabs: main time and additional time. Main view model contains main hours an开发者_高级运维d additional hours as properties, first tab bound to main hours, second tab - to additional hours. Each hour has a clear command (DelegateCommand
from Prism
). On the top of TabControl
there is a button with command "Clear all" (CompositeCommand
). Hours are creating in the constructor of main view model.
Issue:
Commands from additional hours are not exists cause of and they are not participate in command "Clear all", and button "Clear all" is not enabled until I select second tab (in the first tab is nothing to clear, but on the secons there is).
I tried to disabled virtualizing in TabControl
but it didn't help me. Also after loading data I call clearCommand.RaiseCanExecuteChanged
for each hour.
Update: When I iterate through hours in debugger and watch if command can execute it's all fine and UI updates properly. But without debugger it's not.
I'm not sure I understand you correctly, but there are two things I can think of that might cause unusual behavior in your design
Prism's
DelegateCommand
does not automatically re-queryCanExecute
if a parameter changes. To verify if this is your problem or not, I'd switch to using aRelayCommand
of some kind.... I often use Galasoft's MVVM LightRelayCommand
when I want a command to automatically re-evaluate it'sCanExecute
when a parameter changesBy default, WPF unloads TabItems that are not visible. So if the
SaveAllButton.Enabled
property is based off ofTab1.SaveButton.Enabled
andTab2.SaveButton.Enabled
, Tab2 has something to save, but Tab1 does not, and Tab1 has focus, then the SaveAll button will be disabled because Tab2 is not visible and therefore, not loaded. To test if this is the case, switch to using something like aListBox
. If it is the case, you can use the code found here to keep your TabControl from unloading non-visible tabs.
精彩评论