Hi,
I have a parent component with child components . I was using bootstrap tab control with each child item in its own bootstrap page. The child components were direct children of the parent component so i was easily able to dynamically update the child components when a property on the parent changes. Now I see the child components become children of the tab item control instead of the parent control . The child components are now no longer accessible from the parent control as they are embedded in tab item content template component. Is the tab control only meant for text /static content and should not be used to embed child controls on sperate pages ?
|
<SfTab>
<TabItems> <TabItem> <ChildContent> <TabHeader Text="Counter"></TabHeader> </ChildContent> <ContentTemplate> <Counter></Counter> </ContentTemplate> </TabItem> <TabItem> <ChildContent> <TabHeader Text="FetchData"></TabHeader> </ChildContent> <ContentTemplate> <FetchData></FetchData> </ContentTemplate> </TabItem> </TabItems> </SfTab> |
Hi ,
I am using Blazor .So in the example you have provided , I now have no way to update <MyControl> from the parent when something on the parent changes because previously I had
<Parent control>
<Child Component ref = "@ChildComponent/>
<Parent>
In the code behind I could access ChildComponent to update state when something changed on the parent , now it is not possible after initial rendering of parent component .
Now I have
<Parent control>
|
<button class="btn btn-primary" @onclick="IncrementCounter">Increment Count to 20</button>
<br /> <br /> <SfTab> <TabItems> <TabItem> <ChildContent> <TabHeader Text="Counter"></TabHeader> </ChildContent> <ContentTemplate> <Counter IncrementAmount="10" @ref="DetailsCounter" /> </ContentTemplate> </TabItem> </TabItems> </SfTab> @code{ Counter DetailsCounter; private void IncrementCounter() { DetailsCounter.IncrementTwentyCount(); DetailsCounter.IncrementCount(); DetailsCounter.RefreshState(); } } |
|
<h1>Counter</h1>
<p>Current count: @currentCount</p> <button class="btn btn-primary" @onclick="IncrementCount">Click me</button> @code { private int currentCount = 0; [Parameter] public int IncrementAmount { get; set; } = 1; public void IncrementCount() { currentCount += IncrementAmount; } public void IncrementTwentyCount() { IncrementAmount = 20; } public void RefreshState() { StateHasChanged(); } } |