@HiuLiu-MSFT
Thank you very much. I got that TextBox working on adopting a simpler solution. Basically, I check the TextBox content when a Button is clicked launching the code stub that uses the TextBox content. If the TextBox numerical content falls outside the range a messageBox alerts the user and the TextBox content is set back to a default value.
However, now I am facing a new challenge and wonder whether the code you sent me could be adapted to my new task.
In MainWindow.XAML I have a ListBox that is used to display a list of strings that can be edited:
** <ListBox x:Name="EditableStructs" Grid.Row="5" Grid.Column="1" Margin="930,62,0,40" SelectionMode="Single" Grid.ColumnSpan="2" Background="PowderBlue" Height="500"
ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.CanContentScroll="True" ItemsSource="{Binding AutoNames,Mode=TwoWay}" HorizontalAlignment="Left" Width="220" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Name="TextInd" Text="{Binding NamInd, Mode=OneWay}" Grid.Column="0" Padding="1,5" HorizontalAlignment="Stretch"/>
<CheckBox IsChecked="{Binding IsAccepted, Mode=TwoWay}" Grid.Column="1" Padding="5,5" VerticalAlignment="Center" HorizontalAlignment="Center" />
<TextBox Text="{Binding StrName, Mode=TwoWay}" Grid.Column="2" HorizontalAlignment="Stretch"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>**
The code-behind in MainWindow.XAML.cs I populate the above ListBox upon clicking a Button:
- public class EditableStructures
{
public int NamInd { get; set; } = new int();
public bool IsAccepted { get; set; } = new bool();
public string StrName { get; set; } = "";
}public static List<EditableStructures> AutoNames { get; set; } = new List<EditableStructures>();***
- PTAccess pt = new PTAccess();
List<string> EditedList = new List<string>();
EditedList = pt.StructuresAutomaticRename(structures);
int j = 1;
foreach (string str in EditedList)
{
AutoNames.Add(new EditableStructures { StrName = str, IsAccepted = false, NamInd = j});
j++;
}
// string DbgList = "" ; // DEBUG PURPOSE
// DbgList = String.Join(" , ", AutoNames.Select(x => x.StrName)); // DEBUG PURPOSE
// MessageBox.Show($"AUTOMATICALLY RENAMED STRUCTURES: \n {DbgList}"); // DEBUG PURPOSE
//............................ Compare Number of Guessed Structure Names With Number Of Structure Names From Velocity DataBase
// ............................ Alert User If Less Than 50% Structures Could Not Be Guessed
int NumGuessed = 0;
int NumOriginal = 0;
var Guessed = AutoNames.Where(m => !string.IsNullOrWhiteSpace(m.StrName)).ToList();
NumGuessed = Guessed.Count;
NumOriginal = strucNames.Count;
MessageBox.Show($" {NumGuessed} structures automatically renamed out of {NumOriginal} patient structures\n", "Is this patient belonging to this trial? ", MessageBoxButton.OK, MessageBoxImage.Information);
UpdateAutoStrucNames();***
*public void UpdateAutoStrucNames()
{
EditableStructs.ItemsSource = (System.Collections.IEnumerable)AutoNames;
}
``***
Some of the ListBox items contain strings that have been "guessed" through the dice coefficient. The code knows the indexes of the items containing "guessed" strings.
My questions:
How can I draw the user's attention to such ListBox elements? Maybe changing their background color or showing the red "!" symbol as you implemented, or some other way.
I would appreciate some help.
Thank you in advance.