if I want to supply a calculated value to a component such as a grid or any parameter really, and if there is no value then I want to leave the value as it was since it is being automatically calculated by that component, such as a default col width.
Basically I want to say parameter = calculated value or if not found leave as it was, i’m struggling with having to provide a value in the ‘or’ case that is affecting the original defaulted value…like this:
Width="@dict.GetValueOrDefault(colWidth, "")"
If I provide the "" as the default then it overrides what the component was doing on its own.
Alternatively:
Width = valueFound ? value : 0;
The zero is now overriding the original value, and I don’t have access to ‘Width’ since it is a parameter of a grid component, not something I can access if that makes sense.
I want to do this:
Width = valueFound ? value : "LEAVE WHATEVER WIDTH WAS ORIGINALLY";
TYIA
Actual example
<DxGrid Data="@data"
@ref="Grid">
<Columns>
@foreach (DataColumn col in data.Columns)
{
<DxGridDataColumn FieldName="@data.colName"
Width="@valueFound ? value : **LEAVE WHATEVER WIDTH WAS ORIGINALLY**
</DxGridDataColumn>
}
</Columns>
2
Answers
What if u do like this?
You’re fighting the Razor syntax. The other answer provided works for a single parameter, but if you have more than one it starts to get very messy.
You can revert to
RenderTreeBuilder
code which is what the Razor compiler actually produces.Or build a method;
and then call it;